Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading