@@ -146,31 +146,33 @@ async function* traverseRoutesConfig(options: {
146146 const metadata : ServerConfigRouteTreeNodeMetadata = {
147147 renderMode : RenderMode . Prerender ,
148148 ...matchedMetaData ,
149- route : currentRoutePath ,
149+ route : path === '' ? currentRoutePath + '/' : currentRoutePath ,
150150 } ;
151151
152152 delete metadata . presentInClientRouter ;
153153
154- // Handle redirects
155- if ( typeof redirectTo === 'string' ) {
156- const redirectToResolved = resolveRedirectTo ( currentRoutePath , redirectTo ) ;
154+ if ( metadata . renderMode === RenderMode . Prerender ) {
155+ // Handle SSG routes
156+ yield * handleSSGRoute (
157+ typeof redirectTo === 'string' ? redirectTo : undefined ,
158+ metadata ,
159+ parentInjector ,
160+ invokeGetPrerenderParams ,
161+ includePrerenderFallbackRoutes ,
162+ ) ;
163+ } else if ( typeof redirectTo === 'string' ) {
164+ // Handle redirects
157165 if ( metadata . status && ! VALID_REDIRECT_RESPONSE_CODES . has ( metadata . status ) ) {
158166 yield {
159167 error :
160168 `The '${ metadata . status } ' status code is not a valid redirect response code. ` +
161169 `Please use one of the following redirect response codes: ${ [ ...VALID_REDIRECT_RESPONSE_CODES . values ( ) ] . join ( ', ' ) } .` ,
162170 } ;
171+
163172 continue ;
164173 }
165- yield { ...metadata , redirectTo : redirectToResolved } ;
166- } else if ( metadata . renderMode === RenderMode . Prerender ) {
167- // Handle SSG routes
168- yield * handleSSGRoute (
169- metadata ,
170- parentInjector ,
171- invokeGetPrerenderParams ,
172- includePrerenderFallbackRoutes ,
173- ) ;
174+
175+ yield { ...metadata , redirectTo : resolveRedirectTo ( metadata . route , redirectTo ) } ;
174176 } else {
175177 yield metadata ;
176178 }
@@ -214,13 +216,15 @@ async function* traverseRoutesConfig(options: {
214216 * Handles SSG (Static Site Generation) routes by invoking `getPrerenderParams` and yielding
215217 * all parameterized paths, returning any errors encountered.
216218 *
219+ * @param redirectTo - Optional path to redirect to, if specified.
217220 * @param metadata - The metadata associated with the route tree node.
218221 * @param parentInjector - The dependency injection container for the parent route.
219222 * @param invokeGetPrerenderParams - A flag indicating whether to invoke the `getPrerenderParams` function.
220223 * @param includePrerenderFallbackRoutes - A flag indicating whether to include fallback routes in the result.
221224 * @returns An async iterable iterator that yields route tree node metadata for each SSG path or errors.
222225 */
223226async function * handleSSGRoute (
227+ redirectTo : string | undefined ,
224228 metadata : ServerConfigRouteTreeNodeMetadata ,
225229 parentInjector : Injector ,
226230 invokeGetPrerenderParams : boolean ,
@@ -239,6 +243,10 @@ async function* handleSSGRoute(
239243 delete meta [ 'getPrerenderParams' ] ;
240244 }
241245
246+ if ( redirectTo !== undefined ) {
247+ meta . redirectTo = resolveRedirectTo ( currentRoutePath , redirectTo ) ;
248+ }
249+
242250 if ( ! URL_PARAMETER_REGEXP . test ( currentRoutePath ) ) {
243251 // Route has no parameters
244252 yield {
@@ -279,7 +287,12 @@ async function* handleSSGRoute(
279287 return value ;
280288 } ) ;
281289
282- yield { ...meta , route : routeWithResolvedParams } ;
290+ const result = { ...meta , route : routeWithResolvedParams } ;
291+ if ( redirectTo !== undefined ) {
292+ result . redirectTo = resolveRedirectTo ( routeWithResolvedParams , redirectTo ) ;
293+ }
294+
295+ yield result ;
283296 }
284297 } catch ( error ) {
285298 yield { error : `${ ( error as Error ) . message } ` } ;
@@ -456,7 +469,6 @@ export async function getRoutesFromAngularRouterConfig(
456469 includePrerenderFallbackRoutes,
457470 } ) ;
458471
459- let seenAppShellRoute : string | undefined ;
460472 for await ( const result of traverseRoutes ) {
461473 if ( 'error' in result ) {
462474 errors . push ( result . error ) ;
0 commit comments