vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.02k stars 26.7k forks source link

Not found in dynamic route does not render #55555

Closed hrasoa closed 1 year ago

hrasoa commented 1 year ago

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/determined-faraday-gflwsg

To Reproduce

Browse https://gflwsg-3000.csb.app/en-us/aaaa

Current vs. Expected behavior

Verify canary release

Provide environment information

all

Which area(s) are affected? (Select all that apply)

App Router, Routing (next/router, next/navigation, next/link)

Additional context

No response

joulev commented 1 year ago

This is not a bug. Use the root app/not-found.tsx for global 404 handling; other not-found.tsx files are only triggered by an explicit notFound.

To have different not-found for different locales, use app/[lang]/[...notFound]/page.tsx.

balazsorban44 commented 1 year ago

Closing, as per the docs, this is expected behavior as also pointed out above:

Good to know: In addition to catching expected notFound() errors, the root app/not-found.js file also handles any unmatched URLs for your whole application. This means users that visit a URL that is not handled by your app will be shown the UI exported by the app/not-found.js file.

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

everythinginjs commented 12 months ago

@balazsorban44, app/not-found.js file works well in development but in the build process i get the following error

build process error:

Screenshot 2023-09-20 at 12 40 28 pm

my folder structure:

Screenshot 2023-09-20 at 12 38 43 pm

env: "next": "13.5.1-canary.1"

@joulev I got confused some discussions say [...not_found] other say [...not-found] you say [...notFound] what the heck is this finally? and I have to point that [...notFound] (or what ever it is called) does not work with optional catch all routes like [[...slug]] and it errors out you can not use both together.

joulev commented 12 months ago

@joulev I got confused some discussions say [...not_found] other say [...not-found] you say [...notFound] what the heck is this finally?

It's just an ordinary catch-all route that catches all routes not matched by other routes. You can name it [...notFound], [...not-found], or even [...tomandjerry], it will still work.

and I have to point that [...notFound] (or what ever it is called) does not work with optional catch all routes like [[...slug]] and it errors out you can not use both together.

Of course, because two catch-alls cannot go together. If you already have a catch-all, use notFound with the local not-found.tsx file.

everythinginjs commented 12 months ago

@balazsorban44 , I relocate not-found.tsx to (pages) group routes now the error is gone.

github-actions[bot] commented 11 months ago

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