Custom route `post/`id` flashing 404 before finally rendering page.
See original GitHub issueI’m currently experiencing a problem with my post/:id
routes where next flashes the 404
page before successfully rendering my component. At first, I thought this was a redux related issues as my post/id
pages are checking the app state to filter
whichever component should be shown using shallow routing.
After discussing this in the slack channel, I added another API call that would retrieve each blog post but quickly found that I still encountered the same issue. I know that this has happened for at least one other developer so i’m wondering if anyone can point me in the right direction? I’m trying to finish up this personal portfolio I built with next.
Below, you can see exactly what’s happening. Everything looks A1 except for that 404 that blinks whenever a specific post is rendered.
The benefits i’ve gained are tremendous however there have been some minor issues like this one that have got me a little puzzled 🤔 . Anyways, let me know if I can provide any additional info. Thanks 😄
Issue Analytics
- State:
- Created 6 years ago
- Reactions:37
- Comments:49 (27 by maintainers)
Top GitHub Comments
So to answer this one once and for all:
href
=> path inside of thepages
directory + the querystringas
=> rendered in the browser url barExample:
You have a url called
/products/:id
pages/product.js
/products/:id
topages/product.js
and provideid
as part ofquery
in getInitialProps:next/link
like this:The reason you have to explicitly provide the
href
andas
is that Next.js is not aware of any other pages on the client side. We don’t send a manifest of all pages to the client side and subsequent routes get lazy-loaded, which is scalable.There is a community package that abstracts away providing
href
andas
by sending a pre-defined manifest of all routes, note that we recommend not sending a full manifest of all possible routes as not doing this is more scaleablehttps://github.com/fridays/next-routes
Also, note that rendering 404 is no longer the default behavior of Next.js. Instead, we reload the page for the Zones feature.
It’s not fixed.