I am trying to render a Not Found page if no routes are found. I have the routes separated as modules. So when I do the switch statement adding the not found page at the bottom of the switch, such as:
const AccessRoutes = () => {
return (
<React.Fragment>
<Route path="/login" exact component={Login}/>
<Route path="/register" exact component={Register} />
<Route path="/forgot-password" exact component={ForgotPassword}/>
</React.Fragment>
)
}
export default () => {
return (
<Switch>
<AccessRoutes/>
<Route render={() => <div>Not found</div>}
</Switch>
)
}
The not found path never gets matched when you enter a path that is not on AccessRoutes
, for example /hey
shows a blank screen. If I put the routes without wrapping them in another component it works.
What am I missing?