Skip to content

Commit 5d03bde

Browse files
ocavueflorian-lefebvreArmandPhilippot
authored
[v6] disallow number in getStaticPaths params (#12608)
Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> Co-authored-by: Armand Philippot <git@armand.philippot.eu>
1 parent 19a4fbe commit 5d03bde

File tree

1 file changed

+37
-0
lines changed
  • src/content/docs/en/guides/upgrade-to

1 file changed

+37
-0
lines changed

src/content/docs/en/guides/upgrade-to/v6.mdx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,43 @@ If you want to keep the old ID generation for backward compatibility reasons, yo
840840

841841
<ReadMore>Learn more about [Heading IDs](/en/guides/markdown-content/#heading-ids).</ReadMore>
842842

843+
### Changed: `getStaticPaths()` cannot return `params` of type number
844+
845+
<SourcePR number="14586" title="fix!: disallow number in getStaticPaths params"/>
846+
847+
In Astro 5.x, `getStaticPaths()` could return `params` of type number, which would always be stringified by Astro. However, that could be confusing because it conflicted with `Astro.params` types.
848+
849+
Astro 6.0 removes this behavior: `getStaticPaths()` must now return string or undefined `params` values.
850+
851+
#### What should I do?
852+
853+
Review your dynamic routes using `getStaticPaths()` and convert any number params to strings:
854+
855+
```astro title="src/pages/post/[id]/[label].astro" del={6,13} ins={7,14}
856+
---
857+
export function getStaticPaths() {
858+
return [
859+
{
860+
params: {
861+
id: 1,
862+
id: "1",
863+
label: "foo",
864+
}
865+
},
866+
{
867+
params: {
868+
id: 2,
869+
id: "2",
870+
label: "bar",
871+
}
872+
},
873+
]
874+
}
875+
---
876+
```
877+
878+
<ReadMore>Learn more about [dynamic SSG routes with `getStaticPaths()`](/en/guides/routing/#static-ssg-mode).</ReadMore>
879+
843880
## Community Resources
844881

845882
Know a good resource for Astro v5.0? [Edit this page](https://github.com/withastro/docs/edit/main/src/content/docs/en/guides/upgrade-to/v6.mdx) and add a link below!

0 commit comments

Comments
 (0)