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.

detect non-existing route on the server side

See original GitHub issue

I’ve got a simple express app that follows the basic structure as described in the server-rendering guide.

My routes are fully defined in the react-router style so I don’t want to add server-side routes for this part of the app.

I would like to set the correct response status when I’m trying to render a route that does not exist (apart from rendering it with the DefaultRoute. Is there a way to detect wether Router.run picked an existing route or went to the fallback route at server-side?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
romeovscommented, Jan 21, 2015

Wow, seems a lot of work for something that simple.

I’m taking another approach now. I just name the NotFound handler and than look for that name in Router.run on the server side:

// file: routes.jsx
var routes = (
  <Route name='app' handler={App}>
    // other routes....
    <NotFoundRoute name='404' handler={MyNotFound} />
  </Route>
);
// file: render.js (server side render file)
Router.run(routes, path, function(Handler, state) {
  var notfound = state.routes.filter(function(route) {
      return router.name === '404';
  }).length > 0;
  if ( notfound ) {
    throw "Route not found!";
  }
});
0reactions
pshrmncommented, Dec 30, 2017

@ESTEBANMURUZABAL You have been commenting on a number of long dead issues. Please use StackOverflow or Reactiflux for asking questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

detect non-existing route on the server side #573 - GitHub
I've got a simple express app that follows the basic structure as described in the server-rendering guide. My routes are fully defined in ......
Read more >
reactjs - How to detect 404 routes (NoMatch) when doing SSR ...
I'm using react-router-dom and I'm implementing SSR (Server Side Rendering) to my web app. I'm having trouble on how to handle 404 routes....
Read more >
Troubleshoot issues with DNS record resolution for public ...
To find the authoritative name servers, check the value in the name server (NS) resource record set of the Route 53 public hosted...
Read more >
React Router DOM: How to handle routing in web apps
How to set the default route in React. To demonstrate how React Router DOM works, we'll create an example React app. You can...
Read more >
Verify Azure ExpressRoute connectivity - troubleshooting guide
This article helps you identify if and where a connectivity issue ... multiple routing configurations based on external BGP (eBGP) can be ...
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