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.

404 page not working for nested routes

See original GitHub issue

Describe the bug

I have a Next.js app with a custom pages/404.tsx file. When accessing a route on the root of the domain that I expect to return a 404, this page renders fine (a.k.a domain.com/broken-url). However, when trying to access nested routes under this that should return the 404 page, the default Next.js 404 template is shown instead (a.k.a domain.com/broken/this)

Expected behavior

When testing this using npm run build and npm run start the expected behaviour of rendering the custom 404 page works.

Steps to reproduce

  1. Create custom /pages/404.tsx
  2. Deploy using this component.
  3. Access domain.com/broken-url you will see the custom 404 page
  4. Access domain.com/broken/thisl you will NOT see the custom 404 page

Versions

Checklist

  • You have reviewed the README and FAQs, which answers several common questions.
  • Please first try using the most recent latest or alpha @sls-next/serverless-component release version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the old serverless-next.js component and the serverless-next.js plugin are deprecated and no longer maintained.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mdsaviancommented, Apr 12, 2021

I’m facing the same issue. I have a custom 404 page, and I’m not redirected to this page. I’m using @sls-next/serverless-component: 1.19.0-alpha.43 next: 10.1.2

0reactions
dphangcommented, Jun 9, 2021

Sounds good, then I think we can close this issue if the latest issues are with Next.js itself

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle 404 pages for nested routes in react-router
Nested routes are common in react ecosystem, but the handling of not found pages is not great with them. Let's understand one of...
Read more >
How to add a 404 page in react with nested routing?
You can use what you have, but change the route to path="*". This will make it so anything that is not a defined...
Read more >
Routing - Remix
Nested Routing is the general idea of coupling segments of the URL to component hierarchy in the UI. We've found that in almost...
Read more >
React Router v6: Handling 404 Pages & Passing Props to Link
So what if we want to render a 404 component if there is no matching route? In general, the webs that we visit...
Read more >
React Router in Depth #5 - Custom 404 Page - YouTube
Watch the whole course now (without ads) on Net Ninja Pro: https://netninja.dev/p/react-router-in-depth ‍ Access the course files on ...
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