Skip to content

Can I "redirect" to a 404 page without changing the url? #9091

Closed Answered by pawelphilipczyk
mattiaz9 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, I'm trying out many new things coming in data router and your question seemed interesting.

I'm not sure if you are asking about 6.4 or in general but I guess this approach will work in any case:

  • Have an app-wide context with notFound boolean
  • Render component as errorElement
  • All this component does is use the context to set notFound to true
  • The Root component renders not found content instead of the regular app and the URL stays the same

See this: https://stackblitz.com/edit/github-vvn3nt?file=src/main.jsx

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@mattiaz9
Comment options

Answer selected by mattiaz9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants