DEV Community

Harish raj
Harish raj

Posted on

browserRouter in react

browser router we often need to create multiple pages such as Home, About, and Contact. Instead of loading a completely new HTML page every time, React can handle navigation using React Router.

npm i react-router-dom in cmd

main.jsx

import { BrowserRouter } from "react-router-dom";
import App from "./App";

function Main() {
return (



);
}

export default Main;

The important part is:

Creating Routes

Inside App.jsx, we can use Routes and Route.

import { Routes, Route } from "react-router-dom";

function App() {
return (

        <Route path="/" element={<Home />} />

        <Route path="/about" element={<About />} />

        <Route path="/contact" element={<Contact />} />

    </Routes>
);
Enter fullscreen mode Exit fullscreen mode

}

export default App;

↓
npm i react-router-dom
↓
BrowserRouter
↓
Routes
↓
Route
↓
Different React Pages

Top comments (0)