question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hello. 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:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
trochcommented, Jun 9, 2017

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.

0reactions
trochcommented, Jun 25, 2017

Fixed with v5

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling 404 errors - Xperience 13 Documentation - Kentico
This page describes the best practices for creating "404 Not Found" pages when developing Xperience sites using the MVC development model.
Read more >
Handling Your 404 Page Properly - Search Engine Journal
Make sure your server returns the proper 404 header when redirecting from the non-existent page. A 404 error is meant to alert you,...
Read more >
How to Create a Great Custom 404 Error Page (with Examples)
404 pages can be annoying. Keep users on your website after something goes wrong with a custom 404 error page that is actually...
Read more >
Error 404 Guide for SEO & Usability (FAQs & More)
404 errors are generally the most common error type. They are also often handled incorrectly by well-meaning people - hence the purpose ofĀ ......
Read more >
Do 404 errors hurt my site? | Google Search Central Blog
Q: Do the 404 errors reported in Webmaster Tools affect my site's ranking? ... Instead of returning a 404 , you could 301...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found