Skip to content
This repository has been archived by the owner on Dec 15, 2018. It is now read-only.

Trouble implementing 404s with forNoMatch #231

Open
richsilv opened this issue Sep 8, 2017 · 1 comment
Open

Trouble implementing 404s with forNoMatch #231

richsilv opened this issue Sep 8, 2017 · 1 comment
Labels

Comments

@richsilv
Copy link

richsilv commented Sep 8, 2017

Firstly, thanks for a great alternative to react-router.

I'm struggling to work out how to implement a 404 page though, which seems to be what forNoMatch is intended for. Unfortunately, it doesn't really seem to do the trick as it will greedily match urls through the hierarchy you define in your parent React component.

For example, if I change one of the links in the demo to /dog/foobar, which is clearly not a valid path based on either routes.js or demo.js, I still don't see the 404 content when I click on it because the url has already matched /dog, which is resolved to /dog* in resolveCurrentRoute. As a result you just get a page with no content, as there's no matching route in routes.js, but the 404 component is nowhere to be seen.

The only work around for this I can think of is to list all valid routes in the route configuration (whether there's any data associated with them or not) and then have a top-level wrapper component which displays the 404 content rather than the Fragment tree if the current router state has no result.

Could you let me know if I'm missing something here? Is there a way to achieve this using forNoMatch Fragments?

@tptee tptee added the question label Oct 18, 2017
@cjcenizal
Copy link

I wonder if this is related to #232, route-matching being too greedy.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants