React ~ Router ~ 404 Pages - rohit120582sharma/Documentation GitHub Wiki

A common use case for when you’re building a web app is to have a “catch all” route that will be rendered if none of your other routes match. A common example of this would be a 404 page.

By wrapping your Routes inside of Switch, React Router will only render the first Route that matches.


React Router (v4)

<Switch>
    <Route exact path="/" component={Home}/>
    <Route exact path="/profile" component={Profile}/>
    <Route component={FourZeroFour} />
</Switch>

React Router (v5)

<Switch>
    <Route exact path="/">
        <Home />
    </Route>
    <Route exact path="/profile">
        <Profile />
    </Route>
    <Route path="*">
        <FourZeroFour />
    </Route>
</Switch>
⚠️ **GitHub.com Fallback** ⚠️