@@ -154,7 +154,16 @@ export class AngularServerApp {
154154 return null ;
155155 }
156156
157- if ( matchedRoute . renderMode === RenderMode . Prerender ) {
157+ const { redirectTo, status, renderMode } = matchedRoute ;
158+ if ( redirectTo !== undefined ) {
159+ // Note: The status code is validated during route extraction.
160+ // 302 Found is used by default for redirections
161+ // See: https://developer.mozilla.org/en-US/docs/Web/API/Response/redirect_static#status
162+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
163+ return Response . redirect ( new URL ( redirectTo , new URL ( request . url ) ) , ( status as any ) ?? 302 ) ;
164+ }
165+
166+ if ( renderMode === RenderMode . Prerender ) {
158167 const response = await this . handleServe ( request , matchedRoute ) ;
159168 if ( response ) {
160169 return response ;
@@ -186,7 +195,7 @@ export class AngularServerApp {
186195 return null ;
187196 }
188197
189- const { url , method } = request ;
198+ const { method } = request ;
190199 if ( method !== 'GET' && method !== 'HEAD' ) {
191200 return null ;
192201 }
@@ -228,18 +237,7 @@ export class AngularServerApp {
228237 matchedRoute : RouteTreeNodeMetadata ,
229238 requestContext ?: unknown ,
230239 ) : Promise < Response | null > {
231- const { redirectTo, status } = matchedRoute ;
232- const url = new URL ( request . url ) ;
233-
234- if ( redirectTo !== undefined ) {
235- // Note: The status code is validated during route extraction.
236- // 302 Found is used by default for redirections
237- // See: https://developer.mozilla.org/en-US/docs/Web/API/Response/redirect_static#status
238- // eslint-disable-next-line @typescript-eslint/no-explicit-any
239- return Response . redirect ( new URL ( redirectTo , url ) , ( status as any ) ?? 302 ) ;
240- }
241-
242- const { renderMode, headers } = matchedRoute ;
240+ const { renderMode, headers, status } = matchedRoute ;
243241 if (
244242 ! this . allowStaticRouteRender &&
245243 ( renderMode === RenderMode . Prerender || renderMode === RenderMode . AppShell )
@@ -292,7 +290,9 @@ export class AngularServerApp {
292290 } ) ;
293291 }
294292
293+ const url = new URL ( request . url ) ;
295294 let html = await assets . getIndexServerHtml ( ) . text ( ) ;
295+
296296 // Skip extra microtask if there are no pre hooks.
297297 if ( hooks . has ( 'html:transform:pre' ) ) {
298298 html = await hooks . run ( 'html:transform:pre' , { html, url } ) ;
0 commit comments