0

Using ReactJS frontend, with react-router, I somehow get an empty page when being redirected to a new route.

In a component I use the following to achieve a redirect:

if (this.props.showUnknownErrorPage) {
    return <Redirect push to={`/${this.props.locale}/unforeseenerror/`}/>
}

This does lead to the correct URL:

http://127.0.0.1:8000/en/unforeseenerror/

But the page that shows is totally empty, just a blank page.

The route that should get the component to show:

<Route path={`${this.props.match.path}/unforeseenerror/`}
   render={(props) => <UnknownErrorPage {...props}
                                        setGreeneryAppState={this.setGreeneryAppState}/>}
/>

I have similar routes that look quite the same, and they work without problem. Can anyone help me debug this?

What I have already tried:

  • Changed component content, to just an H1 element (no difference)
  • Changed to different route: a one line route like this:

    <Route path={${this.props.match.path}/about} component={AboutPage}/>

  • Tried a hardcoded route path /en/unforeseenerror/

`

Rik Schoonbeek
  • 2,501
  • 1
  • 15
  • 30
  • just to make sure we covered all the obvious scenarios - have you registered the component in your actual router object? I assume that if the other route works you know you need to register it so just making sure you didn't forget on this one? it should look something like this https://github.com/obiwankenoobi/react-express-boilerplate/blob/master/client/src/Screens/Main/Main.js – obiwankenoobi Oct 05 '18 at 13:17
  • Try using the exact prop, if you have any other routes configured with the same url path – Manoj Kumar Oct 05 '18 at 14:05
  • @obiwankenoobi I haven't heard the term registering before, but as I have posted above, inside the route component I am rendering the UnknowErrorPage. I am doing this in the same way that I am doing this in other Routes, even tried it without props (having the Route component on a single line, with component={UnknownErrorPage}, but that didn't work either. Is that what you mean by registering? – Rik Schoonbeek Oct 06 '18 at 10:46
  • @RikSchoonbeek check the repo I shared. This is what I meant by register – obiwankenoobi Oct 06 '18 at 10:49

0 Answers0