diff --git a/.changeset/honest-seas-raise.md b/.changeset/honest-seas-raise.md new file mode 100644 index 000000000000..4d9725290329 --- /dev/null +++ b/.changeset/honest-seas-raise.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes a bug where the custom status code wasn't correctly computed in the dev server diff --git a/packages/astro/src/core/redirects/helpers.ts b/packages/astro/src/core/redirects/helpers.ts index 1faab7c4ecfe..e171aebe6624 100644 --- a/packages/astro/src/core/redirects/helpers.ts +++ b/packages/astro/src/core/redirects/helpers.ts @@ -36,8 +36,8 @@ export function redirectRouteGenerate(redirectRoute: RouteData, data: Params): s export function redirectRouteStatus(redirectRoute: RouteData, method = 'GET'): ValidRedirectStatus { const routeData = redirectRoute.redirectRoute; - if (typeof routeData?.redirect === 'object') { - return routeData.redirect.status; + if (routeData && typeof redirectRoute.redirect === 'object') { + return redirectRoute.redirect.status; } else if (method !== 'GET') { return 308; } diff --git a/packages/astro/src/core/routing/manifest/create.ts b/packages/astro/src/core/routing/manifest/create.ts index 247a01ad1896..fcb31c1cc9b8 100644 --- a/packages/astro/src/core/routing/manifest/create.ts +++ b/packages/astro/src/core/routing/manifest/create.ts @@ -477,7 +477,13 @@ export function createRouteManifest( pathname: pathname || void 0, prerender: false, redirect: to, - redirectRoute: routes.find((r) => r.route === to), + redirectRoute: routes.find((r) => { + if (typeof to === 'object') { + return r.route === to.destination; + } else { + return r.route === to; + } + }), fallbackRoutes: [], };