I have a pages router app with a custom 404 that doesn't take.
Answered
Bee posted this in #help-forum
BeeOP
The files is at pages/404.js and contains this:
just like it says here:
https://nextjs.org/docs/pages/building-your-application/routing/custom-error#customizing-the-404-page
But it never takes - I get the default 404 from next. If I create a new next app it works fine. What should I look for in my app that would cause this?
My project is running Next 14.2.3
export default function Custom404() {
return <h1>404 - Page Not Found</h1>;
}just like it says here:
https://nextjs.org/docs/pages/building-your-application/routing/custom-error#customizing-the-404-page
But it never takes - I get the default 404 from next. If I create a new next app it works fine. What should I look for in my app that would cause this?
My project is running Next 14.2.3
Answered by Bee
in the root of the pages directory we have a file
[...slug].js which is a wildcard catch all route which means the 404.js file never has the chance to kick into action. In the [...slug].js file we look up the url path aka slug in our cms and see if it is an existing page. If it isn't then we just return some JSX saying the page is not found3 Replies
BeeOP
Ok the issue was I have a catch all wildcard route and I have to handle it there.
@Bee Ok the issue was I have a catch all wildcard route and I have to handle it there.
Polar bear
can u explain how did u did it
or screenshot code
or screenshot code
BeeOP
in the root of the pages directory we have a file
[...slug].js which is a wildcard catch all route which means the 404.js file never has the chance to kick into action. In the [...slug].js file we look up the url path aka slug in our cms and see if it is an existing page. If it isn't then we just return some JSX saying the page is not foundAnswer