Skip to content

Commit a4f90d9

Browse files
authoredJan 10, 2024
fix(redirects): correctly compute the status code in redirects (#9657)
1 parent a1b56ee commit a4f90d9

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed
 

‎.changeset/honest-seas-raise.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"astro": patch
3+
---
4+
5+
Fixes a bug where the custom status code wasn't correctly computed in the dev server

‎packages/astro/src/core/redirects/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export function redirectRouteGenerate(redirectRoute: RouteData, data: Params): s
3636

3737
export function redirectRouteStatus(redirectRoute: RouteData, method = 'GET'): ValidRedirectStatus {
3838
const routeData = redirectRoute.redirectRoute;
39-
if (typeof routeData?.redirect === 'object') {
40-
return routeData.redirect.status;
39+
if (routeData && typeof redirectRoute.redirect === 'object') {
40+
return redirectRoute.redirect.status;
4141
} else if (method !== 'GET') {
4242
return 308;
4343
}

‎packages/astro/src/core/routing/manifest/create.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,13 @@ export function createRouteManifest(
477477
pathname: pathname || void 0,
478478
prerender: false,
479479
redirect: to,
480-
redirectRoute: routes.find((r) => r.route === to),
480+
redirectRoute: routes.find((r) => {
481+
if (typeof to === 'object') {
482+
return r.route === to.destination;
483+
} else {
484+
return r.route === to;
485+
}
486+
}),
481487
fallbackRoutes: [],
482488
};
483489

0 commit comments

Comments
 (0)
Please sign in to comment.