Skip to content

Instantly share code, notes, and snippets.

@qnxdev
Created May 4, 2020 04:58
Show Gist options
  • Save qnxdev/ccae69c52247a2e785821ed32281f5a4 to your computer and use it in GitHub Desktop.
Save qnxdev/ccae69c52247a2e785821ed32281f5a4 to your computer and use it in GitHub Desktop.
Create 404 Page for in React
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