unexpected params in getStaticProps
See original GitHub issueBug report
Describe the bug
I’m getting unexpected or undocumented results for getStaticProps with a dynamic route parameter. The params slug is an array of path parts (looks like path.split('/')
). It occurs for me when the page is in a dynamic folder and named index.js and not with a spread filename ie [...slug].js
. Here’s an example:
Problem case:
// at pages/abc/[slug]/index.js
export async function getStaticProps({ params }) {
console.log(params); // --- @build: { slug: 'a' } @runtime: { slug: ['abc', 'a'] }
}
What I expected:
// at pages/abc/[slug]/index.js
export async function getStaticProps({ params }) {
console.log(params); // { slug: 'some-slug' }
}
I get these errors at runtime after deploying to now serverless. Builds are successful and the page appears to work but found the error in the now function logs.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:33 (9 by maintainers)
Top Results From Across the Web
NextJS - getStaticPaths - Paths seems not bound to one of the ...
NextJS - getStaticPaths - Paths seems not bound to one of the params · You can explicitly trigger a 404 page in your...
Read more >Next.js query params inside getStaticProps (Incremental Static ...
Have you ever wondered how to access query parameters "context.req.query" inside getStaticProps ???In this video we will look at a possible ...
Read more >Why can't I get query params in ```getStaticProps```?-Reactjs
getInitialProps and getServerSideProps can know all the possible query params because the page is generated at runtime, whenever you receive a new request....
Read more >Efficient SSG in Next.js with WPGraphQL
In this article, I will discuss best practices around Static Site Generation in Next.js with dynamic routes and static paths.
Read more >getStaticProps slug param returning favicon.ico : r/nextjs - Reddit
But there is an unexpected/strange behavior going on. Let's say I enter in /user/page/example. When I console.log(params.slug), it prints " ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For anyone else stumbling on this, I wrote this ugly fix that seems to catch the edge cases I’ve hit so far:
Ideally in this iteration: https://github.com/vercel/next.js/milestone/46