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:
parent
383c2abc1f
commit
2d89492d73
4 changed files with 28 additions and 1 deletions
5
.changeset/gorgeous-cameras-smile.md
Normal file
5
.changeset/gorgeous-cameras-smile.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fixes a bug that caused pages that return an empty array from getStaticPath to match every path
|
|
@ -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
|
||||
|
|
18
packages/astro/test/fixtures/routing-priority/src/pages/empty-paths/[...slug].astro
vendored
Normal file
18
packages/astro/test/fixtures/routing-priority/src/pages/empty-paths/[...slug].astro
vendored
Normal 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>
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue