question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dynamic nested route matches where it should 404

See original GitHub issue

Bug report

Describe the bug

Give the pages structure

/pages
  /[post]
    /[comment].js
  /user
    /home.js

When you visit the url /user/non-existing it will render /[post]/[comment].js instead of 404. It’s clear that the developer intends for the /user prefix to be its own subsection, so when visiting routes in that subsection it is unexpected to match anything form the /[post] folder.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Example at https://codesandbox.io/s/goofy-moore-mmi49
  2. Go to /user/non-existing
  3. Observe

Expected behavior

It should 404

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
timneutkenscommented, Feb 16, 2020

This is expected behavior imo. You have a dynamic top level route and it matches that.

Eg if the behavior you described would be implemented zeit.co would break on user account routes / dashboard routes

0reactions
balazsorban44commented, Jan 29, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dynamic nested route matches where it should 404 #10550
Go to /user/non-existing; Observe. Expected behavior. It should 404. The text was updated successfully, but these errors were ...
Read more >
Handle 404 pages for nested routes in react-router
One of the major challenge with nested routes is to handle Not found pages. Now as the routes are nested , there is...
Read more >
Dynamic Routes Details - Next.js
Here is some essential information you should know about dynamic routes. ... then any paths not returned by getStaticPaths will result in a...
Read more >
How to render page 404 on dynamic routes : React
The url is matched and it will show the LocationPage component. What you can do it is show an empty location component when...
Read more >
Routing - Remix
Nested Routes - The general idea of routes mapping to segments of the URL allowing the full URL to map to a hierarchy...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found