Skip to content

Instantly share code, notes, and snippets.

@itsmacr8
Created October 9, 2023 16:59
Show Gist options
  • Save itsmacr8/9dd1be2f0d1c1d6d007315e8ab4de24d to your computer and use it in GitHub Desktop.
Save itsmacr8/9dd1be2f0d1c1d6d007315e8ab4de24d to your computer and use it in GitHub Desktop.
How to use react router library for navigation.
import {Routes, Route, Link} from 'react-router-dom'
import Homepage from './Homepage';
import AboutMe from './AboutMe';
function App() {
return(
<div>
<nav>
<Link to="/">Homepage</Link>
<Link to="/about-me">About Me</Link>
</nav>
<Routes>
<Route path="/" element={<Homepage />} />
<Route path="/about-me" element={<AboutMe />} />
</Routes>
</div>
);
}
import ReactDom from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom'
import App from './App';
const root = ReactDom.createRoot(document.getElementById('root'));
root.render(
<BrowserRouter>
<App />
</BrowserRouter>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment