1

Let's say I have these routes:

   <Switch>
    <Route path="/my-profile" component={MyProfile} />
    <Route path="/logout" component={Logout} />
    <Route component={NotFound} />
   </Switch>

Handling 404 page works okay if I type anything other than my-profile or logout in the address bar. However, if I will type .../my-profile/paththatdoesntexist, I will still see the profile page. How to handle such cases? to show not found page regardless of how much nested the path is.

mcmxc
  • 376
  • 4
  • 17

1 Answers1

1

You can use the exact prop in react-router-4 as follows in your routes.

<Switch>
  <Route exact path="/my-profile" component={MyProfile} />
  <Route exact path="/logout" component={Logout} />
  <Route component={NotFound} />
 </Switch>

For more reference you could read here exact: bool