Created
May 4, 2020 04:58
-
-
Save qnxdev/ccae69c52247a2e785821ed32281f5a4 to your computer and use it in GitHub Desktop.
Create 404 Page for in React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In App.js | |
First add import | |
import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; | |
Then, | |
in Class in render() method in Routes, | |
render() { | |
return ( | |
<Router> | |
<Switch> | |
<Route exact path='/'><Home /></Route> //Home Page maybe | |
<Route ><Error /></Route> //Error is the 404 Page Component. | |
</Switch> | |
</Router> | |
); | |
} | |
Now for every /anything/not/valid/url it will show Error Page. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment