404 Handling
See original GitHub issueHello. First of all, great routing solution š
I have one issue, but Iām not sure if Iām doing the right thing. I ended up with route config like this:
export default [
{name: 'home', path: '/'},
// also some routes here
{name: '404', path: '*splat'},
]
With this config the problem is that splat route which I use for 404 page takes precedence over home route and only on router.start
. If I navigate to home
after router.start
by clicking a link, it works ok. I donāt understand the entire codebase, but I noticed that here route-node
is pushing home route after splat route https://github.com/troch/route-node/blob/2a49f9f8668c740a22e1e90bde1b03fb324b00c0/modules/RouteNode.js#L110
May be thatās causing an issue, not sure.
Thatās one part of the problem. The other part is why I ended up defining such route for 404. The reason is that middlewares are not called if I get to 404 route with allowNotFound: true
or defaultRoute: 404
. Iāve got an auth middleware which redirects to login page if user is not logged in.
So the behavior with allowNotFound: true
or defaultRoute: 404
was that if unauthenticated person navigates to route that exist, middleware redirects him to login page. But when he navigates to route that doesnāt exist, middleware is not called and he sees 404. I would like to redirect to login page in both cases.
Can you please suggest a solution to this?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Hey,
Spats wonāt work well in that context. For 404s, use
allowNotFound
option on the router: http://router5.github.io/docs/router-options.html. If the router canāt match the current path, it will generate a ānot foundā state.Fixed with v5