Using "react-router-dom": "^5.3.2"
In my component I have the following code:
render() {
return <div role="main">
<Switch>
<Route path="/auth" exact component={Auth} />
<PrivateRoute path="/" exact component={() => <>Main page</>} />
<IsGranted for={[ 'superuser' ]}>
<PrivateRoute path="/servers" exact component={ServerList} />
</IsGranted>
{/* or even nested in a <></> */}
<Route component={_ => <h1>Not found</h1>} />
</Switch>
</div>
}
const PrivateRoute = ({ component:Component, ...rest }) =>
<Route {...rest} render={props => isAuthenticated() ? <Component {...props}/> : <Redirect to={{ pathname:'/auth', state:{ from:props.location } }}/> }/>
const IfGranted = ({ children }) => condition() ? children : null
The problem is, everything below the empty tag <> is ignored.
For example, I expect Not found be rendered, if I type in some gibberish in the URL.
That happens only, if the <>...</> is commented out.
Is there anything I can do here?