vitepress 2.0.0-alpha.6 → 2.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -222,7 +222,7 @@ function normalizeHref(href) {
222
222
  }
223
223
  return url.pathname + url.search + url.hash;
224
224
  }
225
- async function changeRoute(href, { smoothScroll = false, initialLoad = false } = {}) {
225
+ async function changeRoute(href, { smoothScroll = false, initialLoad = false, replace = false } = {}) {
226
226
  const loc = normalizeHref(location.href);
227
227
  const nextUrl = new URL(href, location.origin);
228
228
  const currentUrl = new URL(loc, location.origin);
@@ -233,9 +233,14 @@ async function changeRoute(href, { smoothScroll = false, initialLoad = false } =
233
233
  }
234
234
  }
235
235
  else {
236
- // save scroll position before changing URL
237
- history.replaceState({ scrollPosition: window.scrollY }, '');
238
- history.pushState({}, '', href);
236
+ if (replace) {
237
+ history.replaceState({}, '', href);
238
+ }
239
+ else {
240
+ // save scroll position before changing URL
241
+ history.replaceState({ scrollPosition: window.scrollY }, '');
242
+ history.pushState({}, '', href);
243
+ }
239
244
  if (nextUrl.pathname === currentUrl.pathname) {
240
245
  // scroll between hash anchors on the same page, avoid duplicate entries
241
246
  if (nextUrl.hash !== currentUrl.hash) {
@@ -27,6 +27,7 @@ interface Router {
27
27
  go: (to: string, options?: {
28
28
  initialLoad?: boolean;
29
29
  smoothScroll?: boolean;
30
+ replace?: boolean;
30
31
  }) => Promise<void>;
31
32
  /**
32
33
  * Called before the route changes. Return `false` to cancel the navigation.