How to Setup React Router v6? | Tutorial 2026 (Step-by-Step Guide for Beginners ๐Ÿš€)

How to Setup React Router v6 Tutorial 2026

Key Highlights ๐Ÿ“Œ

  • โœ… Learn How to Setup React Router v6? | Tutorial 2026 from scratch.
  • โœ… Install React Router DOM the right way.
  • โœ… Understand BrowserRouter, Routes, and Route.
  • โœ… Create multiple pages in React.
  • โœ… Navigate using the Link component.
  • โœ… Learn nested routes with simple examples.
  • โœ… Avoid common beginner mistakes.
  • โœ… Best practices for React Router in 2026.

How to Setup React Router v6? | Tutorial 2026

source by:Medium

If you’ve been wondering How to Setup React Router v6? | Tutorial 2026, you’re in exactly the right place. ๐Ÿ˜Š

When I first started learning React, one thing confused me more than components or hooksโ€”it was routing. My React app worked perfectly, but every time I wanted another page like Home, About, or Contact, I had no idea how people switched between them without refreshing the browser.

That’s when I discovered React Router v6, and honestly, everything started making sense.

In this beginner-friendly guide, I’ll show you How to Setup React Router v6? | Tutorial 2026 step by step using simple language and practical examples. Even if you’ve never used routing before, you’ll finish this guide with a working multi-page React application.

Let’s get started! ๐Ÿš€


What is React Router v6?

Before learning How to Setup React Router v6? | Tutorial 2026, let’s understand what React Router actually does.

Imagine you’re visiting an online shopping website.

When you click:

  • ๐Ÿ  Home
  • ๐Ÿ‘• Products
  • ๐Ÿ“ž Contact
  • ๐Ÿ‘ค Profile

Notice something?

The page changes almost instantly.

It doesn’t reload the entire website.

That’s exactly what React Router v6 helps us do.

It allows us to move between pages inside a React application while keeping everything smooth and fast.

Simply put,


Why Do We Need React Router? ๐Ÿค”

source by:Browsee

Without routing, your React app would become one very long page.

Imagine building:

  • An E-commerce website
  • A Hospital Management System
  • A Student Portal
  • Netflix
  • Instagram

Would you place everything inside one page?

Definitely not.

With React Router v6 Setup, you can organize your application into separate pages while keeping the user experience seamless.


Prerequisites Before React Router v6 Setup

Before starting How to Setup React Router v6? | Tutorial 2026, make sure you have:

  • โœ… Node.js installed
  • โœ… React project created
  • โœ… VS Code
  • โœ… Basic React knowledge

If you don’t have a React project yet, create one:

npx create-react-app my-app

Move into the project:

cd my-app

Start it:

npm start

Step 1: Install React Router DOM

The first step in How to Setup React Router v6? | Tutorial 2026 is installing React Router.

Run:

npm install react-router-dom

That’s it.

React Router DOM is now available in your project.


Step 2: Create Your Pages

Inside the src folder, create a folder called:

pages

Now create these files:

Home.js

About.js

Contact.js

Example:

Home.js

function Home() {
    return <h1>Home Page</h1>;
}

export default Home;

About.js

function About() {
    return <h1>About Page</h1>;
}

export default About;

Contact.js

function Contact() {
    return <h1>Contact Page</h1>;
}

export default Contact;

Simple, right? ๐Ÿ˜Š


Step 3: Import React Router Components

source by:ScholarHat

Now comes the exciting part of React Router v6 Tutorial.

Open App.js

Import:

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

These three components are the heart of React Router v6 Setup.


Step 4: Configure BrowserRouter

Wrap your application inside BrowserRouter.

<BrowserRouter>

</BrowserRouter>

Think of BrowserRouter as the manager that watches every URL change.

Whenever the URL changes, BrowserRouter decides which page should appear.


Step 5: Add Routes

Now define your routes.

<BrowserRouter>

<Routes>

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

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

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

</Routes>

</BrowserRouter>

Now your React app knows:

  • “/” โ†’ Home
  • “/about” โ†’ About
  • “/contact” โ†’ Contact

Congratulations! ๐ŸŽ‰

You have completed the basic React Router v6 Setup.


Step 6: Add Navigation Links

Without links, users can’t move between pages.

Import:

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

Example:

<nav>

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

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

<Link to="/contact">Contact</Link>

</nav>

Now clicking each link changes the page instantly.

No refresh.

No loading screen.

Just smooth navigation.

That’s one of my favorite things about React.


Complete React Router Example

sourceby:Contentful

Here’s a complete example of How to Setup React Router v6? | Tutorial 2026.

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

import Home from "./pages/Home";
import About from "./pages/About";
import Contact from "./pages/Contact";

function App() {

return (

<BrowserRouter>

<nav>

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

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

<Link to="/contact">Contact</Link>

</nav>

<Routes>

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

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

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

</Routes>

</BrowserRouter>

);

}

export default App;

Understanding BrowserRouter, Routes, and Route

When I first learned React Router, I kept mixing these up. Here’s the easiest way I remember them:

ComponentPurpose
BrowserRouterWatches the URL
RoutesHolds all routes
RouteDisplays a component for a URL

Think of it like this:

๐Ÿข BrowserRouter = Building

๐Ÿšช Routes = Hallway

๐Ÿšฉ Route = Individual rooms

Simple visualization always helped me remember it.


Nested Routes in React Router v6

source by:DEV Community

As your project grows, you’ll probably want pages inside other pages.

Example:

Dashboard

Dashboard/Profile

Dashboard/Settings

This is where nested routes become useful.

Example:

<Route path="/dashboard" element={<Dashboard />}>

<Route path="profile" element={<Profile />} />

<Route path="settings" element={<Settings />} />

</Route>

Nested routing keeps large applications clean and organized.


Common Mistakes Beginners Make โŒ

I made almost every one of these mistakes when I started. If you avoid them, you’ll save yourself a lot of debugging time!

  • โŒ Forgetting to install react-router-dom
  • โŒ Using component instead of element (React Router v6 uses element)
  • โŒ Forgetting to wrap the app with BrowserRouter
  • โŒ Typing the wrong path
  • โŒ Importing components from the wrong folder
  • โŒ Using <a> tags instead of <Link> for internal navigation

Best Practices for React Router v6 in 2026 ๐ŸŒŸ

As your React projects grow, these habits will make your code easier to manage:

  • โœ… Keep all pages inside a pages folder.
  • โœ… Use meaningful route names like /products or /profile.
  • โœ… Prefer <Link> over regular HTML anchor tags for internal navigation.
  • โœ… Split large apps into reusable components.
  • โœ… Plan your routes before building the application.

These simple practices have saved me a lot of time on larger projects.


Frequently Asked Questions (FAQs)

Is React Router v6 free?

Yes. React Router is completely free and open-source.


Can I use React Router without React?

No. React Router is specifically designed for React applications.


What is BrowserRouter?

BrowserRouter monitors the browser’s URL and renders the correct React component without refreshing the page.


Why do we use Link instead of <a>?

<Link> allows smooth client-side navigation without reloading the page, while an HTML <a> tag refreshes the browser.


Is React Router v6 beginner-friendly?

Absolutely! Once you understand BrowserRouter, Routes, and Route, creating multi-page React applications becomes much easier.


Final Thoughts ๐ŸŽฏ

Learning How to Setup React Router v6? | Tutorial 2026 felt intimidating to me at first, but once I built my first multi-page app, everything clicked. If you’re just starting out, don’t worry if routing seems confusing initially. Practice by creating small projects with a few pages, experiment with different routes, and gradually explore advanced features like nested routes and route parameters.

The more you build, the more natural React Router will feel. Before long, you’ll be creating smooth, professional-looking React applications with confidence. Happy coding! ๐Ÿš€

Want to learn more about React ?, Kaashiv Infotech Offers React course and more Visit Their website www.kaashivinfotech.com.


Related Reads:

Previous Article

All About Loops in JavaScript: A Comprehensive Guide (With Simple Examples That Finally Made It Click for Me!) ๐Ÿš€

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam โœจ