diff --git a/.changeset/tidy-peas-accept.md b/.changeset/tidy-peas-accept.md new file mode 100644 index 0000000000..fa580f0734 --- /dev/null +++ b/.changeset/tidy-peas-accept.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes preview server `trailingSlash` handling for request URLs with query strings diff --git a/packages/astro/src/core/preview/vite-plugin-astro-preview.ts b/packages/astro/src/core/preview/vite-plugin-astro-preview.ts index 9faabe29b2..b07b88b7ad 100644 --- a/packages/astro/src/core/preview/vite-plugin-astro-preview.ts +++ b/packages/astro/src/core/preview/vite-plugin-astro-preview.ts @@ -24,7 +24,8 @@ export function vitePluginAstroPreview(settings: AstroSettings): Plugin { return; } - const pathname = stripBase(req.url!, base); + const strippedPathname = stripBase(req.url!, base); + const pathname = new URL(strippedPathname, 'https://a.b').pathname const isRoot = pathname === '/'; // Validate trailingSlash