Add React Router to Vite project
14 April 2024 (Updated 16 July 2024)
Install:
npm i react-router-dom
Render router in src/main.tsx
ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
</React.StrictMode>,
)
Add some routes:
import * as React from "react";
import { Routes, Route } from "react-router-dom";
function App() {
return (
<div className="App">
<h1>Welcome to React Router!</h1>
<Routes>
<Route path="/" element={<Home />} />
<Route path="about" element={<About />} />
</Routes>
</div>
);
}
Tagged:
React tooling
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment