Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
How does React Router handle navigation in a React application?
Next article icon

How does React Router handle navigation in a React application?

Last Updated : 28 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

React Router is a standard library for routing in React. It enables the navigation among views of various components in a React Application, allows changing the browser URL, and keeps the UI in sync with the URL. Let us create a simple application to React to understand how the React Router works

React Router simplifies navigation in React applications by providing a declarative approach to define routes and their corresponding components using JSX syntax. It supports nested routing, route parameters, and programmatic navigation, that allows for dynamic and hierarchical navigation structures.

Approach to Handle navigation Using Link

Link is a component provided by React Router DOM that creates a hyperlink to navigate to a different route in your application. It's typically used as a replacement for the <a> tag to navigate between different views in a React application without a page reload. When you click on a Link component, React Router DOM handles the navigation without a full page refresh.

Steps to create React App with React Router

Step 1: Create the react Application using the following command.

npx create-react-app navigation

Step 2: Now move into the project's directory

cd navigation

Step 3: Installing React Router using the following command.

npm install react-router-dom

Folder Structure:

project-structure

The updated dependencies in package.json file will look like:

"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.3",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
}

Example: Create the following folders s seen in folder structure and add the following codes.

JavaScript
// App.js   import {     BrowserRouter as Router,     Routes,     Route, } from "react-router-dom"; import Home from './Components/Home'; import Contact from './Components/Contact'; import About from './Components/About'; import Welcome from './Components/Welcome'; import Blog from './Components/Blog';  function App() {     return (         <>             <Router>                 <Welcome />                 <Routes>                     <Route path="/" element={<Home />} />                     <Route path="about" element={<About />} />                     <Route path="contact" element={<Contact />} />                     <Route path="blog" element={<Blog />} />                 </Routes>             </Router>         </>     ); }  export default App; 
JavaScript
// Home.js  import React from 'react'  const Home = () => {     return (         <div style={{ color: "#00FFBF" }}>In <b>Home</b> page...</div>     ) }  export default Home 
JavaScript
// Contact.js  import React from 'react'  const Contact = () => {     return (         <div style={{ color: "#62b6cb" }}> In <b>Contact</b> page...</div>     ) }  export default Contact 
JavaScript
// Blog.js  import React from 'react'  const Blog = () => {     return (         <div style={{ color: "#a594f9" }}>In <b>Blog</b> page...</div>     ) }  export default Blog 
JavaScript
// About.js  import React from 'react'  const About = () => {     return (         <div style={{ color: "#f72585" }}>In <b>About</b> page...</div>     ) }  export default About 
JavaScript
// Welcome.js  import React from 'react' import { Link } from 'react-router-dom'  const Welcome = () => {     return (         <>             <h3>Welcome to GFG</h3>             <h5> React app: Navigation using Link</h5>             <ul>                 <li><Link to='/'>Home</Link></li>                 <li><Link to='about'>About</Link></li>                 <li><Link to='contact'>Contact</Link></li>                 <li><Link to='blog'>Blog</Link></li>             </ul>         </>     ) }  export default Welcome 

Output:

Animation46


Next Article
How does React Router handle navigation in a React application?

R

rekhans1f1i
Improve
Article Tags :
  • Web Technologies
  • ReactJS
  • ReactJS-Router

Similar Reads

    Mastering React Routing: Learn Navigation and Routing in React Apps
    React Routing is a technique used to handle navigation within a React application. It enables users to move between different views, pages, or components without refreshing the entire page, which is a key feature of Single Page Applications (SPAs).In this article, we will explore the essential conce
    6 min read
    How to Navigate on Path by Button Click in React Router ?
    Navigation in React JS is done by implementing the routing between components using react-router-dom. To set navigation for components or events like button click, we can use the useHistory Hook provided in the react-router-dom v5.Prerequisites:NPM & Node.jsReact JSReact-Router-DomApproachNaviga
    3 min read
    Navigate Component in React Router
    In React applications, navigation between different pages or views is an essential part of creating dynamic user interfaces. React Router is a popular library used for handling routing and navigation. One of the key features of React Router is the Navigate component, which allows for programmatic re
    7 min read
    How to Set Up Vite for a Multi-Page Application?
    Vite is a frontend development tool, used to build projects and multiple page applications in React.js. It is a beginner-friendly user tool that was developed by the founder of Vue.js, another framework of React.js. we will learn how to set up Vite for a Multi-Page Application. Steps to Set Up Vite
    5 min read
    How to Use Routing with React Navigation in React Native ?
    Almost every mobile application requires navigating between different screens. React Native provides an elegant and easy-to-use library to add navigation to native applications: react-navigation. It is one of the most popular libraries used for routing and navigating in a React Native application.Tr
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences