Skip to content

Commit e750e4e

Browse files
alan-agius4alxhub
authored andcommitted
fix(router): provide more actionable error message when route is not matched in production mode (#53523)
Prior to this commit when a route is not matched and the application was running in production mode an `[Error]: NG04002` was logged in the console. This however, is not actionable when the application is running on the server where there can be multiple pages being rendered at the same time. Now we change this to also log the route example: `[Error]: NG04002: 'products/Jeep'`. Closes #53522 PR Close #53523
1 parent a603338 commit e750e4e

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

packages/router/src/apply_redirects.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ export function canLoadFails(route: Route): Observable<LoadedRouterConfig> {
5858
export class ApplyRedirects {
5959
constructor(private urlSerializer: UrlSerializer, private urlTree: UrlTree) {}
6060

61-
noMatchError(e: NoMatch): any {
62-
return new RuntimeError(
63-
RuntimeErrorCode.NO_MATCH,
64-
(typeof ngDevMode === 'undefined' || ngDevMode) &&
65-
`Cannot match any routes. URL Segment: '${e.segmentGroup}'`);
66-
}
67-
6861
lineralizeSegments(route: Route, urlTree: UrlTree): Observable<UrlSegment[]> {
6962
let res: UrlSegment[] = [];
7063
let c = urlTree.root;

packages/router/src/recognize.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ export class Recognizer {
5656
private paramsInheritanceStrategy: ParamsInheritanceStrategy,
5757
private readonly urlSerializer: UrlSerializer) {}
5858

59-
private noMatchError(e: NoMatch): any {
59+
private noMatchError(e: NoMatch): RuntimeError<RuntimeErrorCode.NO_MATCH> {
6060
return new RuntimeError(
6161
RuntimeErrorCode.NO_MATCH,
62-
(typeof ngDevMode === 'undefined' || ngDevMode) &&
63-
`Cannot match any routes. URL Segment: '${e.segmentGroup}'`);
62+
(typeof ngDevMode === 'undefined' || ngDevMode) ?
63+
`Cannot match any routes. URL Segment: '${e.segmentGroup}'` :
64+
`'${e.segmentGroup}'`);
6465
}
6566

6667
recognize(): Observable<{state: RouterStateSnapshot, tree: UrlTree}> {

0 commit comments

Comments
 (0)