Skip to content

Commit

Permalink
fix: don't match all paths when returning empty array from getStaticP…
Browse files Browse the repository at this point in the history
…aths (#12906)
  • Loading branch information
ascorbic authored Jan 6, 2025
1 parent 383c2ab commit 2d89492
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-cameras-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a bug that caused pages that return an empty array from getStaticPath to match every path
1 change: 0 additions & 1 deletion packages/astro/src/core/render/params-and-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
5 changes: 5 additions & 0 deletions packages/astro/test/routing-priority.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 2d89492

Please sign in to comment.