Reputation: 4873
How I can display something like page not found in a define route path, but with not valid slug? Example:
I have defined route with path /about
:
<Switch>
// other routes
<Route path="/about" component={AboutPage} />
<Route component={PageNotFound} />
</Switch>
I got about page component, but I have the wrong slug (or not defined) after route (in my case /about
), how to catch that and display not found page in example code above.
Thanks. o/
Upvotes: 0
Views: 274
Reputation: 1146
The reason you still get to the About page is because you're still matching the path. If you only want to go to a route if the path match is exact, you can pass the exact
flag to the Route: <Route exact path='/about' component={AboutPage} />
Upvotes: 1