- Forums
- Tutorial and Guides
- React Vite - How To Add A Route With Component
This Page Contains information about React Vite - How To Add A Route With Component By dd in category Tutorial and Guides with 0 Replies. [5045], Last Updated: Mon Jun 24, 2024
dd
Mon Dec 26, 2022
0 Comments
723 Visits
To add a new route to your Vite/React application follow these steps:
- Install React router:
$ npm install react-router-dom localforage match-sorter sort-by
- Open main.jsx, import react router and add the BrowserRouter:
import { BrowserRouter } from 'react-router-dom'
ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<BrowserRouter>
<App />
</BrowserRouter>
</React.StrictMode>,
)
- Open App.jsx and make it like this:
import { Link, Route, Routes } from 'react-router-dom'
import Navigation from "./components/Navigation"
import Home from "./components/Home"
function App() {
return (
<div className="bg-slate-100">
<Navigation />
<Routes>
<Route path="/home" element={<Home />} />
</Routes>
<h1>Welcome</h1>
</div>
)
}
export default App
- For more information visit https://reactrouter.com/en/main/start/tutorial