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

Nested dynamic route segment doesn't redirect to root not-found.js #48609

Open
1 task done
jeslenbucci opened this issue Apr 20, 2023 · 5 comments
Open
1 task done

Nested dynamic route segment doesn't redirect to root not-found.js #48609

jeslenbucci opened this issue Apr 20, 2023 · 5 comments
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template.

Comments

@jeslenbucci
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: #1 SMP Wed Aug 25 23:20:18 UTC 2021
    Binaries:
      Node: 18.14.2
      npm: 9.6.4
      Yarn: 1.22.19
      pnpm: N/A
    Relevant packages:
      next: 13.3.0
      eslint-config-next: 13.3.0
      react: 18.2.0
      react-dom: 18.2.0

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

App directory (appDir: true)

Link to the code that reproduces this issue

n/a

To Reproduce

Using the app directory, create several folders for path segments with the last ending in a dynamic route. Here is my example:

app/(site)/memberships/benefits/[slug]/page.js

I have several other similar to this

Describe the Bug

When a dynamic path is nested within another folder path, the notFound() function does not redirect to the /not-found.js page. It instead throws an error. All other paths work fine. This is true whether the nested dynamic route is [slug] or [...slug]

Expected Behavior

I expect that the notFound() function should redirect to the not-found.js page like the other dynamic routes in this same project do.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

@jeslenbucci jeslenbucci added the bug Issue was opened via the bug report template. label Apr 20, 2023
@github-actions github-actions bot added the area: app App directory (appDir: true) label Apr 20, 2023
@guillermo-avalos
Copy link

guillermo-avalos commented Apr 29, 2023

I'm having a similar issue. My app structure goes something like this

app/(blog)/posts/[postSlug]/page.js

And I also have a loading.js and a not-found.js in the /posts/ directory. The loader works just fine (I'm rendering a skeleton of the blog post while it loads), but the notFound() function is not returning me /posts/not-found.js and instead returns the not-found.js at the app's root.

app/
└─ not-found.js
└─ layout.js
└─ page.js
├─ (admin)/
└─ (blog)/
     ├─ layout.js
     ├─ page.js
     └─ /posts/
          └─ not-found.js
          └─ /[postSlug]/
                 └─  page.js

In this scenario, when /posts/[postSlug]/page.js returns notFound(), I'm not getting /posts/not-found.js but instead app/not-found.js

@adiletelf
Copy link

I'm having similar issue. My folder structure looks like this:
app/[locale]/not-found.tsx
I am using next-intl so I need to use [locale] part to understand which language user prefers. The problem is that Next.js only looks for root not-found file in app/not-found.tsx and does not display app/[locale]/not-found.tsx.

If I place not-found.tsx in the root, then I don't know which locale to display. Either I need to find the solution or find other ways to provide localization for my Next.js website.

@CanRau
Copy link

CanRau commented May 29, 2023

Same here, tried to put it in various places, also put console.logs in all not-found.tsx files and apparently all get called though only app/not-found.tsx get's rendered 🤷🏼

Also it's missing the layout of the same dir level

@M4Tdev
Copy link

M4Tdev commented Dec 17, 2023

Did anyone come up with something to make it work?

@beelzick
Copy link

Same error next 14.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: app App directory (appDir: true) bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

6 participants