FormidableLabs / redux-little-router

A tiny router for Redux that lets the URL do the talking.
MIT License
1.04k stars 114 forks source link

Trouble implementing 404s with forNoMatch #231

Open richsilv opened 7 years ago

richsilv commented 7 years ago

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?

cjcenizal commented 6 years ago

I wonder if this is related to https://github.com/FormidableLabs/redux-little-router/issues/232, route-matching being too greedy.