@simonbackx/vue-app-navigation 2.8.0 → 2.8.1

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.
package/dist/index.js CHANGED
@@ -276,15 +276,20 @@ class HistoryManagerStatic {
276
276
  });
277
277
  });
278
278
  }
279
- resolveUrl(url, index) {
280
- if (url !== null) {
281
- return "/" + UrlHelper.trim(UrlHelper.transformUrl(url));
279
+ getStateUrl(index) {
280
+ if (index < 0) {
281
+ return "";
282
282
  }
283
- if (!this.states[index - 1]) {
284
- return "/" + UrlHelper.trim(UrlHelper.transformUrl("/"));
283
+ if (!this.states[index]) {
284
+ return this.getStateUrl(index - 1);
285
285
  }
286
- const previousUrl = this.states[index - 1].url;
287
- return this.resolveUrl(previousUrl ?? null, index - 1);
286
+ if (this.states[index].url !== null) {
287
+ return this.states[index].url;
288
+ }
289
+ return this.getStateUrl(index - 1);
290
+ }
291
+ resolveUrl(index) {
292
+ return "/" + UrlHelper.trim(UrlHelper.transformUrl(this.getStateUrl(index)));
288
293
  }
289
294
  /// Set the current URL without modifying states
290
295
  setUrl(url, title, index) {
@@ -306,7 +311,7 @@ class HistoryManagerStatic {
306
311
  if (this.counter !== count || state.url !== url) {
307
312
  return;
308
313
  }
309
- const formattedUrl = this.resolveUrl(url, count);
314
+ const formattedUrl = this.resolveUrl(count);
310
315
  history.replaceState({ counter: count }, "", formattedUrl);
311
316
  if (state.title) {
312
317
  window.document.title = this.formatTitle(state.title);
@@ -345,7 +350,7 @@ class HistoryManagerStatic {
345
350
  }
346
351
  this.addToQueue(() => {
347
352
  const lastState = this.states[this.states.length - 1];
348
- const formattedUrl = this.resolveUrl(lastState.url ?? null, lastState.index);
353
+ const formattedUrl = this.resolveUrl(lastState.index);
349
354
  history.replaceState({ counter: this.counter }, "", formattedUrl);
350
355
  });
351
356
  }
@@ -375,6 +380,16 @@ class HistoryManagerStatic {
375
380
  getCurrentState() {
376
381
  return this.states[this.counter];
377
382
  }
383
+ getState(index) {
384
+ if (index < 0) {
385
+ return null;
386
+ }
387
+ const s = this.states[index];
388
+ if (s && s.index === index) {
389
+ return s;
390
+ }
391
+ return this.getState(index - 1);
392
+ }
378
393
  pushState(url, undoAction, options) {
379
394
  if (!this.active) {
380
395
  return;
@@ -1396,7 +1411,9 @@ const NavigationController$1 = defineComponent({
1396
1411
  comp.keepAlive = true;
1397
1412
  }
1398
1413
  }
1399
- HistoryManager.invalidateHistory();
1414
+ if (this.components.length !== components.length) {
1415
+ HistoryManager.invalidateHistory();
1416
+ }
1400
1417
  } else {
1401
1418
  this.components.push(...components);
1402
1419
  }
@@ -1420,10 +1437,12 @@ const NavigationController$1 = defineComponent({
1420
1437
  }
1421
1438
  } else {
1422
1439
  for (const component2 of components) {
1423
- HistoryManager.pushState(void 0, null, {
1424
- adjustHistory,
1425
- invalid: options.invalidHistory ?? !!replace
1426
- });
1440
+ if (!replace || this.components.length !== components.length) {
1441
+ HistoryManager.pushState(void 0, null, {
1442
+ adjustHistory,
1443
+ invalid: options.invalidHistory ?? !!replace
1444
+ });
1445
+ }
1427
1446
  component2.assignHistoryIndex();
1428
1447
  }
1429
1448
  }
@@ -2052,7 +2071,7 @@ function normalizePushOptions(o, currentComponent, urlHelpers) {
2052
2071
  if (options.url !== void 0) {
2053
2072
  const url = options.url;
2054
2073
  for (const component of options.components) {
2055
- component.provide.reactive_navigation_url = computed(() => url === null ? null : urlHelpers.extendUrl(url));
2074
+ component.provide.reactive_navigation_url = computed(() => url === null ? null : urlHelpers.extendUrl(url, { returnHistory: options.replace ?? 0 }));
2056
2075
  }
2057
2076
  }
2058
2077
  return options;
@@ -2156,6 +2175,7 @@ function useUrl() {
2156
2175
  const currentComponent = useCurrentComponent();
2157
2176
  const navigationUrl = inject("reactive_navigation_url", null);
2158
2177
  const disableUrl = inject("reactive_navigation_disable_url", null);
2178
+ const historyIndex = inject("navigation_historyIndex", null);
2159
2179
  return {
2160
2180
  getUrl() {
2161
2181
  return unref(navigationUrl) ?? "";
@@ -2175,8 +2195,17 @@ function useUrl() {
2175
2195
  currentComponent.setTitle(title);
2176
2196
  }
2177
2197
  },
2178
- extendUrl(url) {
2179
- const prefix = this.getUrl();
2198
+ extendUrl(url, options = {}) {
2199
+ let prefix = this.getUrl();
2200
+ if (options.returnHistory) {
2201
+ console.log("returnHistory", options.returnHistory);
2202
+ const index = unref(historyIndex);
2203
+ if (index !== null && index !== void 0) {
2204
+ prefix = HistoryManager.getStateUrl(index - options.returnHistory);
2205
+ } else {
2206
+ console.error("Failed to get history index");
2207
+ }
2208
+ }
2180
2209
  if (prefix && prefix !== "/") {
2181
2210
  return prefix + "/" + UrlHelper.trim(url);
2182
2211
  }
@@ -30,7 +30,8 @@ declare class HistoryManagerStatic {
30
30
  private addToQueue;
31
31
  private runQueue;
32
32
  private go;
33
- resolveUrl(url: HistoryUrl, index: number): string;
33
+ getStateUrl(index: number): string;
34
+ resolveUrl(index: number): string;
34
35
  setUrl(url: HistoryUrl, title?: string, index?: number): void;
35
36
  updateUrl(): void;
36
37
  formatTitle(title: string): string;
@@ -39,6 +40,7 @@ declare class HistoryManagerStatic {
39
40
  */
40
41
  setTitle(title: string, index?: number): void;
41
42
  getCurrentState(): HistoryState;
43
+ getState(index: number): HistoryState | null;
42
44
  pushState(url: string | undefined, undoAction: ((animate: boolean) => void | Promise<void>) | null, options?: Partial<HistoryState>): void;
43
45
  /**
44
46
  * Call when an action is performed that breaks back/forward navigation
@@ -95,7 +95,9 @@ export declare function useUrl(): {
95
95
  * Ideally call this after you've processed all the .match() calls (and awaited async stuff)
96
96
  */
97
97
  setTitle(title: string): void;
98
- extendUrl(url: string): string;
98
+ extendUrl(url: string, options?: {
99
+ returnHistory?: number;
100
+ }): string;
99
101
  match<Params>(template: string, params?: UrlParamsConstructors<Params>): UrlMatchResult<Params> | undefined;
100
102
  matchCurrent<Params>(template: string, params?: UrlParamsConstructors<Params>): UrlMatchResult<Params> | undefined;
101
103
  overrideUrl(url: HistoryUrl, title?: string): void;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@simonbackx/vue-app-navigation",
3
3
  "main": "./dist/index.js",
4
4
  "types": "./dist/index.d.ts",
5
- "version": "2.8.0",
5
+ "version": "2.8.1",
6
6
  "exports": {
7
7
  ".": {
8
8
  "import": "./dist/index.js",