()
| 191 | |
| 192 | private eventsSubscription = new Subscription(); |
| 193 | private subscribeToNavigationEvents() { |
| 194 | const subscription = this.navigationTransitions.events.subscribe((e) => { |
| 195 | try { |
| 196 | const currentTransition = this.navigationTransitions.currentTransition; |
| 197 | const currentNavigation = untracked(this.navigationTransitions.currentNavigation); |
| 198 | |
| 199 | if (currentTransition !== null && currentNavigation !== null) { |
| 200 | this.stateManager.handleRouterEvent(e, currentNavigation); |
| 201 | if ( |
| 202 | e instanceof NavigationCancel && |
| 203 | e.code !== NavigationCancellationCode.Redirect && |
| 204 | e.code !== NavigationCancellationCode.SupersededByNewNavigation |
| 205 | ) { |
| 206 | // It seems weird that `navigated` is set to `true` when the navigation is rejected, |
| 207 | // however it's how things were written initially. Investigation would need to be done |
| 208 | // to determine if this can be removed. |
| 209 | this.navigated = true; |
| 210 | } else if (e instanceof NavigationEnd) { |
| 211 | this.navigated = true; |
| 212 | this.injectorCleanup?.(this.routeReuseStrategy, this.routerState, this.config); |
| 213 | } else if (e instanceof RedirectRequest) { |
| 214 | const opts = e.navigationBehaviorOptions; |
| 215 | const mergedTree = this.urlHandlingStrategy.merge( |
| 216 | e.url, |
| 217 | currentTransition.currentRawUrl, |
| 218 | ); |
| 219 | const extras = { |
| 220 | scroll: currentTransition.extras.scroll, |
| 221 | browserUrl: currentTransition.extras.browserUrl, |
| 222 | info: currentTransition.extras.info, |
| 223 | skipLocationChange: currentTransition.extras.skipLocationChange, |
| 224 | // The URL is already updated at this point if we have 'eager' URL |
| 225 | // updates or if the navigation was triggered by the browser (back |
| 226 | // button, URL bar, etc). We want to replace that item in history |
| 227 | // if the navigation is rejected. |
| 228 | replaceUrl: |
| 229 | currentTransition.extras.replaceUrl || |
| 230 | this.urlUpdateStrategy === 'eager' || |
| 231 | isBrowserTriggeredNavigation(currentTransition.source), |
| 232 | // allow developer to override default options with RedirectCommand |
| 233 | ...opts, |
| 234 | }; |
| 235 | |
| 236 | this.scheduleNavigation(mergedTree, IMPERATIVE_NAVIGATION, null, extras, { |
| 237 | resolve: currentTransition.resolve, |
| 238 | reject: currentTransition.reject, |
| 239 | promise: currentTransition.promise, |
| 240 | }); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | // Note that it's important to have the Router process the events _before_ the event is |
| 245 | // pushed through the public observable. This ensures the correct router state is in place |
| 246 | // before applications observe the events. |
| 247 | if (isPublicRouterEvent(e)) { |
| 248 | this._events.next(e); |
| 249 | } |
| 250 | } catch (e: unknown) { |
no test coverage detected