Skip to content

Commit

Permalink
fix(router): provide more actionable error message when route is not …
Browse files Browse the repository at this point in the history
…matched in production mode (angular#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 angular#53522

PR Close angular#53523
  • Loading branch information
alan-agius4 authored and danieljancar committed Jan 26, 2024
1 parent 9ae6a1a commit dfef2ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
7 changes: 0 additions & 7 deletions packages/router/src/apply_redirects.ts
Expand Up @@ -58,13 +58,6 @@ export function canLoadFails(route: Route): Observable<LoadedRouterConfig> {
export class ApplyRedirects {
constructor(private urlSerializer: UrlSerializer, private urlTree: UrlTree) {}

noMatchError(e: NoMatch): any {
return new RuntimeError(
RuntimeErrorCode.NO_MATCH,
(typeof ngDevMode === 'undefined' || ngDevMode) &&
`Cannot match any routes. URL Segment: '${e.segmentGroup}'`);
}

lineralizeSegments(route: Route, urlTree: UrlTree): Observable<UrlSegment[]> {
let res: UrlSegment[] = [];
let c = urlTree.root;
Expand Down
7 changes: 4 additions & 3 deletions packages/router/src/recognize.ts
Expand Up @@ -56,11 +56,12 @@ export class Recognizer {
private paramsInheritanceStrategy: ParamsInheritanceStrategy,
private readonly urlSerializer: UrlSerializer) {}

private noMatchError(e: NoMatch): any {
private noMatchError(e: NoMatch): RuntimeError<RuntimeErrorCode.NO_MATCH> {
return new RuntimeError(
RuntimeErrorCode.NO_MATCH,
(typeof ngDevMode === 'undefined' || ngDevMode) &&
`Cannot match any routes. URL Segment: '${e.segmentGroup}'`);
(typeof ngDevMode === 'undefined' || ngDevMode) ?
`Cannot match any routes. URL Segment: '${e.segmentGroup}'` :
`'${e.segmentGroup}'`);
}

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

0 comments on commit dfef2ab

Please sign in to comment.