@real-router/angular 0.24.5 → 0.24.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.
package/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
  npm install @real-router/angular @real-router/core @real-router/browser-plugin
11
11
  ```
12
12
 
13
- **Peer dependencies:** `@angular/core` >= 22.0.0, `@angular/common` >= 22.0.0
13
+ **Peer dependencies:** `@real-router/core`, `@angular/core` >= 22.0.0, `@angular/common` >= 22.0.0
14
14
 
15
15
  ## Quick Start
16
16
 
@@ -591,7 +591,7 @@ The URL hash tracks the topmost visible anchor as the user scrolls, syncing `sta
591
591
 
592
592
  Options: `{ selector: string, rootMargin?: string, scrollContainer?: () => HTMLElement | null }`. Default `rootMargin`: `"-20% 0px -60% 0px"`. Empty `selector` / `undefined` = off. SSR / browsers without `IntersectionObserver` = NOOP. Requires `browser-plugin` or `navigation-plugin` (hash-plugin / memory-plugin → warn-once + NOOP). The utility is installed via `provideEnvironmentInitializer` (`installScrollSpy`) and torn down on `DestroyRef`; options are a snapshot at bootstrap, not reactive.
593
593
 
594
- Available on both `provideRealRouter(router, { scrollSpy })` (SPA) and `provideRealRouterFactory({ baseRouter, scrollSpy })` (SSR). On the SSR path the utility is correctly NOOP'd on the server pass (`document` is undefined). Behaviour is identical to the React adapter — see the [React Scroll Spy demo](../../examples/web/react/hash-examples/scroll-spy/) (12 sections, TOC sidebar, 10 e2e scenarios) and the [Scroll Spy guide](https://github.com/greydragon888/real-router/wiki/Scroll-Spy).
594
+ Available on both `provideRealRouter(router, { scrollSpy })` (SPA) and `provideRealRouterFactory({ baseRouter, scrollSpy })` (SSR). On the SSR path the utility is correctly NOOP'd on the server pass (`document` is undefined). Behaviour is identical to the React adapter — see the [React Scroll Spy demo](../../examples/web/react/hash-examples/scroll-spy/) (12 sections, TOC sidebar, Playwright-tested) and the [Scroll Spy guide](https://github.com/greydragon888/real-router/wiki/Scroll-Spy).
595
595
 
596
596
  ## Server-Side Rendering
597
597
 
@@ -789,7 +789,7 @@ The shared (cross-framework) wiki pages use the `use*` naming convention — the
789
789
 
790
790
  | Package | Description |
791
791
  | ---------------------------------------------------------------------------------------- | --------------------------------------- |
792
- | [@real-router/core](https://www.npmjs.com/package/@real-router/core) | Core router (required dependency) |
792
+ | [@real-router/core](https://www.npmjs.com/package/@real-router/core) | Core router (required peer dependency) |
793
793
  | [@real-router/browser-plugin](https://www.npmjs.com/package/@real-router/browser-plugin) | Browser History API integration |
794
794
  | [@real-router/sources](https://www.npmjs.com/package/@real-router/sources) | Subscription layer (used internally) |
795
795
  | [@real-router/route-utils](https://www.npmjs.com/package/@real-router/route-utils) | Route tree queries (`injectRouteUtils`) |
@@ -13,41 +13,51 @@ function createDirectionTracker(router) {
13
13
  let popstateFlag = false;
14
14
  document.documentElement.dataset.navDirection = "forward";
15
15
  let inFlight;
16
- let armedMidTransition = false;
17
- const landsOnRouterState = () => {
18
- const state = router.getState();
16
+ let replay;
17
+ let passedOn = false;
18
+ const hrefOf = (state) => {
19
19
  const buildUrl = router.buildUrl;
20
- if (state === void 0 || buildUrl === void 0) return false;
20
+ if (buildUrl === void 0) return;
21
21
  try {
22
22
  const hash = state.context?.url?.hash;
23
23
  const url = buildUrl(state.name, state.params, state.search, hash ? { hash } : void 0);
24
- return url !== void 0 && new URL(url, globalThis.location.href).href === globalThis.location.href;
24
+ return url === void 0 ? void 0 : new URL(url, globalThis.location.href).href;
25
25
  } catch {
26
- return false;
26
+ return;
27
27
  }
28
28
  };
29
+ const landsOnRouterState = () => {
30
+ const state = router.getState();
31
+ return state !== void 0 && hrefOf(state) === globalThis.location.href;
32
+ };
29
33
  const onPopstate = () => {
30
- if (landsOnRouterState()) return;
31
- popstateFlag = true;
32
- armedMidTransition = inFlight !== void 0;
34
+ if (landsOnRouterState()) {
35
+ if (inFlight === void 0) popstateFlag = false;
36
+ return;
37
+ }
38
+ if (inFlight === void 0) popstateFlag = true;
39
+ else replay = globalThis.location.href;
33
40
  };
34
41
  globalThis.addEventListener("popstate", onPopstate);
35
42
  const api = getPluginApi(router);
36
43
  const onSettled = () => {
37
44
  inFlight = void 0;
38
- if (armedMidTransition) {
39
- armedMidTransition = false;
40
- return;
41
- }
42
- popstateFlag = false;
45
+ popstateFlag = replay !== void 0;
46
+ passedOn = popstateFlag;
47
+ replay = void 0;
43
48
  };
44
49
  const onError = (toState) => {
45
- if (inFlight === void 0 || toState?.context === inFlight.context) onSettled();
46
- else armedMidTransition = false;
50
+ if (inFlight === void 0 || toState?.context === inFlight.context) {
51
+ onSettled();
52
+ return;
53
+ }
54
+ const href = toState === void 0 ? void 0 : hrefOf(toState);
55
+ if (href === void 0 || href === replay) replay = void 0;
47
56
  };
48
57
  const unsubs = [
49
58
  api.addEventListener(events.TRANSITION_START, (toState) => {
50
59
  inFlight = toState;
60
+ if (popstateFlag && !passedOn && landsOnRouterState()) popstateFlag = false;
51
61
  }),
52
62
  api.addEventListener(events.TRANSITION_SUCCESS, onSettled),
53
63
  api.addEventListener(events.TRANSITION_ERROR, onError),
@@ -55,7 +65,6 @@ function createDirectionTracker(router) {
55
65
  router.subscribeLeave(() => {
56
66
  document.documentElement.dataset.navDirection = popstateFlag ? "back" : "forward";
57
67
  popstateFlag = false;
58
- armedMidTransition = false;
59
68
  })
60
69
  ];
61
70
  return { destroy: () => {
@@ -82,7 +91,6 @@ function createRouteAnnouncer(router, options) {
82
91
  if (typeof document === "undefined") return NOOP_INSTANCE$3;
83
92
  const prefix = options?.prefix ?? "Navigated to ";
84
93
  const getCustomText = options?.getAnnouncementText;
85
- let isInitialNavigation = true;
86
94
  let isReady = false;
87
95
  let isDestroyed = false;
88
96
  let lastAnnouncedText = "";
@@ -108,9 +116,10 @@ function createRouteAnnouncer(router, options) {
108
116
  doAnnounce(text, document.querySelector("h1"));
109
117
  }
110
118
  }, SAFARI_READY_DELAY);
111
- const unsubscribe = router.subscribe(({ route }) => {
112
- if (isInitialNavigation) {
113
- isInitialNavigation = false;
119
+ let initialLoadPending = router.getState() === void 0;
120
+ const unsubscribe = router.subscribe(({ route, previousRoute }) => {
121
+ if (previousRoute === void 0 && initialLoadPending) {
122
+ initialLoadPending = false;
114
123
  return;
115
124
  }
116
125
  requestAnimationFrame(() => {