0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00

fix: don't match all paths when returning empty array from getStaticPaths (#12906)

This commit is contained in:
Matt Kane 2025-01-06 11:49:39 +00:00 committed by GitHub
parent 383c2abc1f
commit 2d89492d73
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fixes a bug that caused pages that return an empty array from getStaticPath to match every path

View file

@ -47,7 +47,6 @@ export async function getProps(opts: GetParamsAndPropsOptions): Promise<Props> {
base,
});
if (!staticPaths.length) return {};
// The pathname used here comes from the server, which already encoded.
// Since we decided to not mess up with encoding anymore, we need to decode them back so the parameters can match
// the ones expected from the users

View file

@ -0,0 +1,18 @@
---
export function getStaticPaths() {
return []
}
const { slug } = Astro.params
---
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>{slug}</title>
</head>
<body>
<h1>empty-paths/[...slug].astro</h1>
<p>slug: {slug}</p>
</body>
</html>

View file

@ -107,6 +107,11 @@ const routes = [
url: '/empty-slug/undefined',
fourOhFour: true,
},
{
description: 'do not match /empty-paths/hello to empty-paths/[...slug].astro',
url: '/empty-paths/hello',
fourOhFour: true,
},
{
description: 'matches /api/catch/a.json to api/catch/[...slug].json.ts',
url: '/api/catch/a.json',