Replies: 1 suggested answer
-
Same here, found something about this?? I'm working with redirect before 404 page be rendered and it works well locally, but remote. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Bug report
Describe the bug
I have a setup with an optional catch-all route on the most top level (directly in
pages
directory), which is named[[...slug]].js
, so that I can have pretty URLs (it's a Strapi-backed-up website, by the way). Then, I also have a custom 404 page, which is thepages/404.js
file. If I'm using a<Link>
component fromnext/link
, which has ahref
attribute, pointing to a page that doesn't exist (its path is not one of[[...slug]]
's paths that are fetched ingetStaticPaths()
, then on client-side it tries to render the page[[...slug]]
instead of my custom 404 page. However, when I visit the non-existing page directly or by refreshing the page, I see the custom 404 page. I noticed that this happens whenever I haveexport async function getStaticProps(){}
in my custom 404 page. If I remove it - everything is alright. In case anyone asks - I need the static props in my custom 404 page, because I am fetching some data like the title and the image for this page (they are customizable through Strapi).To Reproduce
pages/[[...slug]].js
to act as a catch-all route of all possible routespages/404.js
withgetStaticProps
next build
next start
and navigate to this non-existing path by clicking on the rendered Link.Expected behavior
I expect to see the custom 404 page by clicking on the Link. Instead - I see "An unexpected error has occurred." and in the console I see errors that indicate it tried to render the
[[...slug]].js
instead.System information
Additional context
Happens only when using the production build. I guess it is this way, because in development there is an automatic page refresh when I try to load a non-existing page.
Beta Was this translation helpful? Give feedback.