How do you implement routing in a React application

0 votes
With the help of code can you tell me How do you implement routing in a React application?
Feb 22, 2025 in Node-js by Ashutosh
• 33,350 points
573 views

1 answer to this question.

0 votes

Implementing Routing in a React Application (React Router)

1. Install React Router

npm install react-router-dom

2. Set Up Routes in App.js

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

import Home from "./Home";

import About from "./About";

const App = () => {

  return (

    <Router>

      <Routes>

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

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

      </Routes>

    </Router>

  );

};

export default App;

3. Create Navigation Links

import { Link } from "react-router-dom";

const Navbar = () => {

  return (

    <nav>

      <Link to="/">Home</Link>

      <Link to="/about">About</Link>

    </nav>

  );

};

export default Navbar;

4. Use in Components

import { useNavigate } from "react-router-dom";

const Home = () => {

  const navigate = useNavigate();

  return <button onClick={() => navigate("/about")}>Go to About</button>;

};

export default Home;

answered Feb 23, 2025 by Kavya

Related Questions In Node-js

0 votes
1 answer

How do you implement breadcrumbs in a React-Router app?

Breadcrumbs help users navigate by showing the ...READ MORE

answered Feb 24, 2025 in Node-js by Kavya
587 views
0 votes
1 answer

How can you implement nested routes in a React application using React Router?

To implement nested routes in a React ...READ MORE

answered Apr 17, 2025 in Node-js by anonymous
594 views
0 votes
1 answer
0 votes
1 answer

How do you pass and use URL parameters in a React-Router route?

Passing and Using URL Parameters in React ...READ MORE

answered Feb 23, 2025 in Node-js by Kavya
513 views
0 votes
1 answer

How would you implement a chat application using MongoDB’s data model patterns?

To implement a chat application using MongoDB’s ...READ MORE

answered Feb 23, 2025 in Node-js by Kavya
568 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to set read concern in MongoDB?

In MongoDB, you can set read concern ...READ MORE

answered Feb 23, 2025 in Node-js by Kavya
618 views
0 votes
1 answer

How would you implement routing in a dynamic Music Store application?

Implementing Routing in a Dynamic Music Store ...READ MORE

answered Feb 23, 2025 in Node-js by Kavya
650 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP