September 2018
Beginner
156 pages
3h 28m
English
As mentioned, the <Switch> component looks through all the <Route> components sequentially for a match and stops the search once a <Route> with its path matching the browser's URL is found. This is unlike a list <Route> in a page, where every matched <Route> is rendered. The <Switch> thus becomes a good fit for rendering a Page Not Found page, that is, rendering a component when none of the <Route> mentioned as children to <Switch> match the browser's URL.
Let's include a <Route> with no path prop as the last entry in <Switch>:
<Switch> <Route path="/login" component={LoginComponent} /> <Route path="/user" render={({ match }) => <div> Route with path {match.url}</div> } /> <Route render={({ location }) =>Read now
Unlock full access