Skip to content

Commit 114bd80

Browse files
committed
refactor: add notes on NavigationCancel and NavigationError events
1 parent ff3a259 commit 114bd80

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

packages/router-component-store/src/lib/router-history-store/router-history.store.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,35 @@ export function provideRouterHistoryStore(): Provider[] {
2626
return [provideComponentStore(RouterHistoryStore)];
2727
}
2828

29+
// TODO(@LayZeeDK): Handle `NavigationCancel` and `NavigationError` events
30+
// NavigationStart -> NavigationEnd | NavigationCancel | NavigationError
31+
//
32+
// NavigationError resets the URL to what it was before the navigation that caused an error. No new *navigation* is triggered.
33+
// NavigationError reasons:
34+
// - Invalid route path
35+
// NavigationError(id: 3, url: '/an-invalid/path', error: Error: Cannot match any routes. URL Segment: 'an-invalid/path')
36+
// - Router resolver throws
37+
// - Route matcher throws
38+
// - Routed component throws in constructor (or a lifecycle hook?)
39+
// - Lazy route chunk file is not found (bundles updated and the user needs to refresh)
40+
// RouterTestingModule.withRoutes([
41+
// {
42+
// path: 'stale-chunk',
43+
// loadChildren: () =>
44+
// Promise.reject({ name: 'ChunkLoadError', message: 'ChunkLoadError' }),
45+
// // or () => { throw { name: 'ChunkLoadError', message: 'ChunkLoadError' }; }
46+
// },
47+
// ]),
48+
//
49+
// What is the URL after each of the following reasons?
50+
// NavigationCancel reasons:
51+
// NavigationCancel#code: NavigationCancellationCode
52+
// - GuardRejected: A navigation failed because a guard returned `false`.
53+
// - NoDataFromResolver: A navigation failed because one of the resolvers completed without emiting a value.
54+
// - Redirect: A navigation failed because a guard returned a `UrlTree` to redirect.
55+
// - SupersededByNewNavigation: A navigation failed because a more recent navigation started.
56+
// NavigationCancel { id: 3, url: "/company", reason: "Navigation ID 3 is not equal to the current navigation id 4" }
57+
2958
@Injectable()
3059
export class RouterHistoryStore extends ComponentStore<RouterHistoryState> {
3160
#router = inject(Router);

0 commit comments

Comments
 (0)