Fallback/404 Child Route Matching #239
Unanswered
reintroducing
asked this question in
Q&A
Replies: 3 comments 5 replies
-
+1 on default not found component implementation |
Beta Was this translation helpful? Give feedback.
3 replies
-
I had the same problem but just thought of a solution: {!find(routes, (r) => location.current.pathname === r.path) && (
<Navigate to="./404" />
)} I'm using lodash for this, ofcourse you can also do it with vanilla js.
|
Beta Was this translation helpful? Give feedback.
1 reply
-
any solution to this yet ? @reintroducing |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to figure out how to add a proper 404 route handler for ALL urls that don't exist. It seems like, to effectively do that, you have to manually add a 404 route at every level of routing (root level, then inside of any children levels as well. I've put together an example to show this here: https://codesandbox.io/s/distracted-hofstadter-kxrjxu?file=/src/index.tsx
If you go to
/foo
it will show the error route, but if you go to/about/foo
it will render theabout
route with nothing for the outlet. I was expecting that, because I had not defined the route at all, it would just render theNoMatch
element like the top level/foo
does. How can I just define the 404 route once and have it permeate throughout all route children so that I don't have to add it into everychildren
array for every set of routes I'm creating?I tried looking through the docs but I could not find anything in regards to this and its seems like the fuzzy matching of child routes is what is preventing this from happening. Is there a pattern/best practice for this?
Beta Was this translation helpful? Give feedback.
All reactions