Created
August 8, 2021 06:22
-
-
Save MeetMartin/49b147d45c57fe6afc98c0c593671e14 to your computer and use it in GitHub Desktop.
React Router In Under 60 Seconds
This file contains hidden or 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
import React from 'react'; | |
const Page404 = () => { | |
return ( | |
<> | |
<p> | |
This is not the page that you are looking for! | |
</p> | |
</> | |
); | |
}; | |
export default Page404; |
This file contains hidden or 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
import React from 'react'; | |
import { BrowserRouter as Router } | |
from 'react-router-dom'; | |
import Routes from './Routes'; | |
const App = () => { | |
return ( | |
<div> | |
<header> | |
<h1> | |
I am everywhere. | |
Router doesn't touch me. | |
</h1> | |
</header> | |
<article> | |
<Router> | |
<Routes /> | |
</Router> | |
</article> | |
</div> | |
); | |
}; | |
export default App; |
This file contains hidden or 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
import React from 'react'; | |
const HomePage = () => { | |
return ( | |
<> | |
<h1>Hello world!</h1> | |
<p>I am a HomePage!</p> | |
</> | |
); | |
}; | |
export default HomePage; |
This file contains hidden or 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
// React Router in under 60 seconds | |
import React from 'react'; | |
import { Route, Switch } | |
from 'react-router-dom'; | |
import Page404 from './pages/404Page'; | |
import HomePage from './pages/HomePage'; | |
const Routes = () => ( | |
<Switch> | |
<Route | |
exact path='/' | |
component={HomePage} | |
/> | |
<Route component={Page404} /> | |
</Switch> | |
); | |
export default Routes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment