next.js icon indicating copy to clipboard operation
next.js copied to clipboard

404 Routes in `/app` directory

Open thezeptar opened this issue 3 years ago • 5 comments

Describe the feature you'd like to request

404 Routes in /app directory

This is a feature request about being able to add 404 routes in the /app directory. There's no exact point to stick with, but I think it will be massively appreciated if this feature gets added.

Describe the solution you'd like

Being able to add a 404 page in the /app directory.

Describe alternatives you've considered

I've been putting my 404 page in my /pages folder.

thezeptar avatar Nov 07 '22 05:11 thezeptar

@Zeptar1069 , Next.js 13 offers alternative way of implementing 404 pages, Documentation link below, in case if you missed out.

https://beta.nextjs.org/docs/api-reference/notfound https://beta.nextjs.org/docs/api-reference/file-conventions/not-found

vigneshshiv avatar Nov 07 '22 06:11 vigneshshiv

@vigneshshiv I added a not-found page to the app/feed but it's not working when I put 404.TSX to the pages directory, it works fine on development mode but it is causing problems after building the app. getting and runtime error on the prod build

RazorRSD avatar Nov 07 '22 08:11 RazorRSD

@RazorRSD Are you using feed as a router inside app directory? If not you can place it in the exact route directory and check. It would be better, if you could provide more details like app structure or any codepen link as a reference.

vigneshshiv avatar Nov 07 '22 08:11 vigneshshiv

It sounds like a bug rather than a feature request, as https://beta.nextjs.org/docs/api-reference/file-conventions/not-found should be the answer here. Could you attach your repo so we can have a look?

balazsorban44 avatar Nov 07 '22 14:11 balazsorban44

I thought I stumbled across the same issues, but while trying to reproduce everything works, which is always great :)

The one thing I would might improve upon is explaining in the not-found documentation that you cant use notFound()/not-found.tsx to handle requests that go towards pages that do not exist. Took some googling to find out I still had to use the pages directory with a 404.tsx file to handle this.

I assume that the not-found.tsx file will replace this some time in the future?

Reproduction repository here if anyone wants to confirm/play around.

Gawdfrey avatar Nov 08 '22 18:11 Gawdfrey

I have been having the same issue, have you find a solution to have a notfound page with the app directory?

mrloldev avatar Nov 10 '22 06:11 mrloldev

I have been having the same issue, have you find a solution to have a notfound page with the app directory?

If you read my comment right above yours, you can find a repository where this is implemented. The app directory does not currently have a global 404 page for non-existent pages, therefore you need to still use the pages directory for this functionality.

Gawdfrey avatar Nov 10 '22 08:11 Gawdfrey

Alright, thank you for all of the support! I've managed to find the solution, thanks to @Gawdfrey and @vigneshshiv

thezeptar avatar Nov 12 '22 23:11 thezeptar

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

github-actions[bot] avatar Dec 13 '22 00:12 github-actions[bot]