Free ATS Friendly Resume Builder Online

Create Your Resume

Resume Builder

Resume Maker

Resume Templates

Resume PDF Download

Create Your Resume is a free online resume builder that helps job seekers create professional, ATS friendly resumes in minutes. Easily build, customize, and download modern resume templates in PDF format.

Our resume maker is designed for freshers and experienced professionals looking to create job-ready resumes. Choose from multiple resume templates, customize sections, and generate ATS optimized resumes online for free.

Create resumes for IT jobs, software developers, freshers, experienced professionals, managers, and students. This free resume builder supports CV creation, resume PDF download, and online resume editing without signup.

Back to React Js
Lesson 35 of 59

React Router Setup: What It Is, How to Set It Up, Routing Types, and Real-World Usage

React Router is the standard routing library used to build single-page applications (SPAs) in React. It enables seamless navigation between pages without full page reloads, improving performance and user experience. This guide explains what React Router is, how to set it up step by step, different routing types, protected routes, nested routes, and real-world use cases. You’ll also learn best practices, common mistakes, and architectural patterns used in production-grade applications. Understanding React Router setup is essential for building scalable, user-friendly React apps with clean navigation and maintainable routing logic.

What is React Router?

React Router is a client-side routing library that allows navigation between different UI views without reloading the page. It keeps the UI in sync with the browser URL and enables Single Page Application (SPA) behavior.

Instead of requesting new HTML pages from the server, React Router swaps components dynamically.

Why Do We Need React Router?

  • Fast navigation without page reload
  • Better user experience
  • Clean and shareable URLs
  • Supports nested and protected routes

Almost all real-world applications like dashboards, portals, and tools similar to multi-step form platforms rely on client-side routing.

Installing React Router

React Router v6 is the latest stable version.


npm install react-router-dom

Basic React Router Setup

Wrap Your App with BrowserRouter


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

const root = ReactDOM.createRoot(document.getElementById("root"));

root.render(
  <BrowserRouter>
    <App />
  </BrowserRouter>
);

BrowserRouter listens to URL changes and renders the matching component.

Defining Routes


import { Routes, Route } from "react-router-dom";
import Home from "./Home";
import About from "./About";

function App() {
  return (
    <Routes>
      <Route path="/" element={<Home />} />
      <Route path="/about" element={<About />} />
    </Routes>
  );
}

Each Route maps a URL path to a React component.

Navigation Using Link


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

function Navbar() {
  return (
    <nav>
      <Link to="/">Home</Link>
      <Link to="/about">About</Link>
    </nav>
  );
}

Unlike anchor tags, Link prevents full page reloads.

Nested Routes


<Route path="/dashboard" element={<Dashboard />}>
  <Route path="profile" element={<Profile />} />
  <Route path="settings" element={<Settings />} />
</Route>

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

function Dashboard() {
  return (
    <div>
      <h2>Dashboard</h2>
      <Outlet />
    </div>
  );
}

Nested routes are commonly used in structured flows like step-based user journeys.

Protected Routes (Authentication)


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

function ProtectedRoute({ isAuth, children }) {
  if (!isAuth) {
    return <Navigate to="/login" />;
  }
  return children;
}

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

This pattern is widely used in secure applications and admin dashboards.

Dynamic Routes (URL Params)


<Route path="/user/:id" element={<User />} />

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

function User() {
  const { id } = useParams();
  return <p>User ID: {id}</p>;
}

Programmatic Navigation


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

function Login() {
  const navigate = useNavigate();

  function handleLogin() {
    navigate("/dashboard");
  }

  return <button onClick={handleLogin}>Login</button>;
}

404 Page (Fallback Route)


<Route path="*" element={<NotFound />} />

Always include a fallback route for better UX.

Common Mistakes

  • Forgetting to wrap app with BrowserRouter
  • Using <a> instead of Link
  • Overusing global route guards
  • Mixing v5 and v6 syntax

Many of these mistakes are highlighted in frontend best-practice articles.

Best Practices & Special Notes

  • Keep routes centralized
  • Lazy load route components
  • Group routes by feature
  • Use loaders for data fetching (v6.4+)

To test routing knowledge and edge cases, scenario-based challenges on interactive assessments are highly effective.

Final Takeaway

React Router is the backbone of navigation in React applications. A clean and well-structured router setup improves performance, security, and scalability. Mastering React Router is essential for building real-world, production-ready React apps.