Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not-found.js does not work within a route group #51075

Closed
1 task done
viniciusbitt opened this issue Jun 9, 2023 · 6 comments · Fixed by #54931
Closed
1 task done

not-found.js does not work within a route group #51075

viniciusbitt opened this issue Jun 9, 2023 · 6 comments · Fixed by #54931
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@viniciusbitt
Copy link

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #22 SMP Tue Jan 10 18:39:00 UTC 2023
    Binaries:
      Node: 16.17.0
      npm: 8.15.0
      Yarn: 1.22.19
      pnpm: 7.1.0
    Relevant packages:
      next: 13.4.5-canary.9
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 4.9.5

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Routing (next/router, next/navigation, next/link)

Link to the code that reproduces this issue or a replay of the bug

https://codesandbox.io/p/sandbox/youthful-zhukovsky-qpjl36

To Reproduce

  1. Create a route group and create not-found.js inside the group.
  2. Navigate to any not found page

Describe the Bug

not-found.js file isn't working within a route group.

Expected Behavior

Reading the documentation I saw that it has no limitation for route group.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@viniciusbitt viniciusbitt added the bug Issue was opened via the bug report template. label Jun 9, 2023
@github-actions github-actions bot added area: app App directory (appDir: true) Navigation Related to Next.js linking (e.g., <Link>) and navigation. labels Jun 9, 2023
@viniciusbitt
Copy link
Author

Related: #50034

@surjithctly
Copy link

I confirm this does not work and created a Stackblitz Reproduction and found this issue.

@dbrxnds
Copy link

dbrxnds commented Jun 14, 2023

Running into this same issue now. I think that's on purpose though, the docs state that only the root not-found page will render for unmatched routes. Not necessarily the nearest one. Although I think it would make sense for it do so.

Edit: I think it could be because it doesn't match a part of the URL, it either matches it completely or not at all.

Some clarification on all of this from the Next team would be great though.

@hughlv
Copy link

hughlv commented Jun 15, 2023

I'm running into this issue too. The problem is related to the use of next-intl, to get all pages (including app/page.tsx) localized properly, we have to put everything under app/(locales) route group. And then not-found.tsx itself became NOT FOUND.

Any workround or fixing suggestions are welcome.

@hughlv
Copy link

hughlv commented Jun 15, 2023

I'm running into this issue too. The problem is related to the use of next-intl, to get all pages (including app/page.tsx) localized properly, we have to put everything under app/(locales) route group. And then not-found.tsx itself became NOT FOUND.

Any workround or fixing suggestions are welcome.

The solution mentioned in #50034 (i.e. adding a [...not-found] route) worked. Saved my day.

@kodiakhq kodiakhq bot closed this as completed in #54931 Sep 3, 2023
kodiakhq bot pushed a commit that referenced this issue Sep 3, 2023
For group routes, as their custom layout show up at the 1st level of the loader tree, so previously we tried to add the default not-found to that layer, but if they have custom root not-found, we should use that as the root not-found componeny, instead of using default not-found component to form the 404 page

Closes NEXT-1588

Fixes #51075
Fixes #54892
@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template. locked Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants