Getting 404 on dynamic routes when not accessing from a <Link />
See original GitHub issueBug report
Describe the bug
I’m getting 404 on production build when trying to first load a dynamic route. If accessing the route from a <Link href="/blog/[slug]" as="/blog/test">[...]</Link>
, the page is correctly rendered.
To Reproduce
git clone https://github.com/zeit/next-learn-demo.git
cd next-learn-demo
cd 8-deploying
yarn
next build && next export
cd out
serve
- Navigate to
http://localhost:5000/p/learn-nextjs
- See
404
Expected behavior
Load the dynamic route correctly, as if it was navigated from a previous page through <Link />
.
System information
- OS: macOS
- Browser: Chrome
- Version of Next.js: 9.2.1
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Getting 404 when first loading dynamic routes on nextjs
When navigating from Home page and clicking into a next/router <Link /> component, the blog post loads correctly, but if I get the...
Read more >Getting 404 on dynamic routes when not accessing ... - GitHub
I'm getting 404 on production build when trying to first load a dynamic route. If accessing the route from a <Link href="/blog/[slug]" as="/blog ......
Read more >Dynamic Routes Details - Next.js
Here is some essential information you should know about dynamic routes. ... then any paths not returned by getStaticPaths will result in a...
Read more >How to return a 404 Not Found page for dynamic routes in ...
If the blog post is not found in the CMS, because it has e.g. been deleted or the slug has changed you can...
Read more >Routing in Next.js – How to Set Up Dynamic Routing with Pre ...
In this tutorial, you'll learn how to set up dynamic routing in Next.js. You'll also learn about pre-rendering and why it's important.
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
According to the docs, depending on your use case, you may not need to use
next export
at all asnext build
is already enough thanks to Automatic Static Optimization.Aside from that, try creating a
next.config.js
file and adding thisexportPathMap
:that way Next will know which route maps to which dynamic route. This example may also be helpful.
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.