Using `getStaticPaths` in combination with `trailingSlash: true` leads to invalid json prefetching
See original GitHub issueBug report
Using getStaticPaths
in combination with trailingSlash: true
leads to invalid json prefetching. For a link to a dynamic route, the json file that is prefetched includes an invalid slash in the path, causing a 404 to be returned. However, when clicking the link and landing on the dynamic page the correct json file is fetched.
To Reproduce
- Configure
// next.config.js
module.exports = {
trailingSlash: true,
};
- Add dynamic route
// pages/[name].js
export default function Hello({ name }) {
return <div>Hello {name}</div>
}
export function getStaticProps(context) {
return {
props: {
name: context.params.name
}
};
}
export function getStaticPaths() {
return {
paths: [
{ params: { name: 'world' } }
],
fallback: false
};
}
- Add link to dynamic route
// pages/index.js
import Link from 'next/link'
export default function Home() {
return (
<div>
<Link as="/world" href="/[name]">
<a>Hello world</a>
</Link>
</div>
)
}
- Export using
next build && next export
- Open root page
- Observe a network request for
https://example.com/_next/data/some-hash/world/.json
returning a 404
Expected behavior
The correct https://example.com/_next/data/some-hash/world.json
is (pre)fetched
System information
- OS: macOs
- Browser (if applies): chrome
- Version of Next.js: 9.5.5
- Version of Node.js: v12.18.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Fetch error when building Next.js static website in production
I use getStaticProps and getStaticPath fetch from an API route. First when I npm run build FetchError: invalid json response body at ...
Read more >Trailing Slash - next.config.js
Configure Next.js pages to resolve with or without a trailing slash. ... getStaticPaths · getStaticProps · Incremental Static Regeneration.
Read more >Next.js Tutorial - 27 - getStaticPaths fallback true - YouTube
Courses - https://learn.codevolution.dev/⚡️ Checkout Taskade! https://www.taskade.com/ Support UPI - https://support.codevolution.dev/ ...
Read more >Next.js Tutorial - 25 - Fetching Paths for getStaticPaths
Courses - https://learn.codevolution.dev/⚡️ Checkout Taskade! https://www.taskade.com/ Support UPI - https://support.codevolution.dev/ ...
Read more >@next/mdx: Versions | Openbase
Disable Image Optimization API when next.config.js has unoptimized: true : # ... Add clarity in docs for using exportPathMap with getStaticPaths : #39813 ......
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
I have exactly the same issue, any updates?
Following on this. It is a really serious issue for our project, as not being able to fetch the pages .json breaks prefetching of links, causing the entire app to re-render when you click on a link and subsequent loss of data in React contexts.