@@ -26,7 +26,7 @@ import { ServerAssets } from '../assets';
26
26
import { Console } from '../console' ;
27
27
import { AngularAppManifest , getAngularAppManifest } from '../manifest' ;
28
28
import { AngularBootstrap , isNgModule } from '../utils/ng' ;
29
- import { joinUrlParts } from '../utils/url' ;
29
+ import { joinUrlParts , stripLeadingSlash } from '../utils/url' ;
30
30
import { PrerenderFallback , RenderMode , SERVER_ROUTES_CONFIG , ServerRoute } from './route-config' ;
31
31
import { RouteTree , RouteTreeNodeMetadata } from './route-tree' ;
32
32
@@ -43,7 +43,10 @@ const VALID_REDIRECT_RESPONSE_CODES = new Set([301, 302, 303, 307, 308]);
43
43
/**
44
44
* Additional metadata for a server configuration route tree.
45
45
*/
46
- type ServerConfigRouteTreeAdditionalMetadata = Partial < ServerRoute > ;
46
+ type ServerConfigRouteTreeAdditionalMetadata = Partial < ServerRoute > & {
47
+ /** Indicates if the route has been matched with the Angular router routes. */
48
+ matched ?: boolean ;
49
+ } ;
47
50
48
51
/**
49
52
* Metadata for a server configuration route tree node.
@@ -124,19 +127,23 @@ async function* traverseRoutesConfig(options: {
124
127
if ( ! matchedMetaData ) {
125
128
yield {
126
129
error :
127
- `The '${ currentRoutePath } ' route does not match any route defined in the server routing configuration. ` +
130
+ `The '${ stripLeadingSlash ( currentRoutePath ) } ' route does not match any route defined in the server routing configuration. ` +
128
131
'Please ensure this route is added to the server routing configuration.' ,
129
132
} ;
130
133
131
134
continue ;
132
135
}
136
+
137
+ matchedMetaData . matched = true ;
133
138
}
134
139
135
140
const metadata : ServerConfigRouteTreeNodeMetadata = {
136
141
...matchedMetaData ,
137
142
route : currentRoutePath ,
138
143
} ;
139
144
145
+ delete metadata . matched ;
146
+
140
147
// Handle redirects
141
148
if ( typeof redirectTo === 'string' ) {
142
149
const redirectToResolved = resolveRedirectTo ( currentRoutePath , redirectTo ) ;
@@ -189,7 +196,9 @@ async function* traverseRoutesConfig(options: {
189
196
}
190
197
}
191
198
} catch ( error ) {
192
- yield { error : `Error processing route '${ route . path } ': ${ ( error as Error ) . message } ` } ;
199
+ yield {
200
+ error : `Error processing route '${ stripLeadingSlash ( route . path ?? '' ) } ': ${ ( error as Error ) . message } ` ,
201
+ } ;
193
202
}
194
203
}
195
204
}
@@ -237,7 +246,7 @@ async function* handleSSGRoute(
237
246
if ( ! getPrerenderParams ) {
238
247
yield {
239
248
error :
240
- `The '${ currentRoutePath } ' route uses prerendering and includes parameters, but 'getPrerenderParams' is missing. ` +
249
+ `The '${ stripLeadingSlash ( currentRoutePath ) } ' route uses prerendering and includes parameters, but 'getPrerenderParams' is missing. ` +
241
250
`Please define 'getPrerenderParams' function for this route in your server routing configuration ` +
242
251
`or specify a different 'renderMode'.` ,
243
252
} ;
@@ -253,7 +262,7 @@ async function* handleSSGRoute(
253
262
const value = params [ parameterName ] ;
254
263
if ( typeof value !== 'string' ) {
255
264
throw new Error (
256
- `The 'getPrerenderParams' function defined for the '${ currentRoutePath } ' route ` +
265
+ `The 'getPrerenderParams' function defined for the '${ stripLeadingSlash ( currentRoutePath ) } ' route ` +
257
266
`returned a non-string value for parameter '${ parameterName } '. ` +
258
267
`Please make sure the 'getPrerenderParams' function returns values for all parameters ` +
259
268
'specified in this route.' ,
@@ -440,6 +449,19 @@ export async function getRoutesFromAngularRouterConfig(
440
449
routesResults . push ( result ) ;
441
450
}
442
451
}
452
+
453
+ if ( serverConfigRouteTree ) {
454
+ for ( const { route, matched } of serverConfigRouteTree . traverse ( ) ) {
455
+ if ( matched ) {
456
+ continue ;
457
+ }
458
+
459
+ errors . push (
460
+ `The server route '${ stripLeadingSlash ( route ) } ' does not match any routes defined in the Angular routing configuration. ` +
461
+ 'Please verify and remove this route from the server configuration.' ,
462
+ ) ;
463
+ }
464
+ }
443
465
} else {
444
466
routesResults . push ( { route : '' , renderMode : RenderMode . Prerender } ) ;
445
467
}
0 commit comments