Created
April 23, 2021 19:25
-
-
Save yann-yinn/032500826cc9192d398d4019298683a4 to your computer and use it in GitHub Desktop.
react router dom
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
import React from "react"; | |
import { | |
BrowserRouter as Router, | |
Switch, | |
Route, | |
Link | |
} from "react-router-dom"; | |
export default function App() { | |
return ( | |
<Router> | |
<div> | |
<nav> | |
<ul> | |
<li> | |
<Link to="/">Home</Link> | |
</li> | |
<li> | |
<Link to="/about">About</Link> | |
</li> | |
<li> | |
<Link to="/users">Users</Link> | |
</li> | |
</ul> | |
</nav> | |
{/* A <Switch> looks through its children <Route>s and | |
renders the first one that matches the current URL. */} | |
<Switch> | |
<Route path="/about"> | |
<About /> | |
</Route> | |
<Route path="/users"> | |
<Users /> | |
</Route> | |
<Route path="/"> | |
<Home /> | |
</Route> | |
</Switch> | |
</div> | |
</Router> | |
); | |
} | |
function Home() { | |
return <h2>Home</h2>; | |
} | |
function About() { | |
return <h2>About</h2>; | |
} | |
function Users() { | |
return <h2>Users</h2>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment