Skip to content

Instantly share code, notes, and snippets.

@jatin510
Last active November 10, 2022 05:59
Show Gist options
  • Save jatin510/7ff09f55d4b2551fee4e0f1335319663 to your computer and use it in GitHub Desktop.
Save jatin510/7ff09f55d4b2551fee4e0f1335319663 to your computer and use it in GitHub Desktop.
Navigation in React
import React from "react";
import { BrowserRouter, Routes, Route, NavLink } from "react-router-dom";
import Home from "./components/Home";
import About from "./components/About";
import Contact from "./components/Contact";
function App() {
return (
<>
<BrowserRouter>
<NavLink exact activeClassName="active" to="/" >
Home
</NavLink>
<NavLink exact activeClassName="active" to="/about" >
About
</NavLink>
<NavLink exact activeClassName="active" to="/contact" >
Contact
</NavLink>
<Routes>
<Route exact path="/" element={<Home />} />
<Route exact path="/about" element={<About />} />
<Route exact path="/contact" element={<Contact />} />
</Routes>
</BrowserRouter>
</>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment