REACT ROUTER /// NAVIGATE /// SINGLE PAGE APPLICATIONS /// ROUTES /// BROWSER ROUTER /// LINK /// REACT ROUTER /// NAVIGATE /// SINGLE PAGE APPLICATIONS /// ROUTES /// BROWSER ROUTER /// LINK ///

React Router

Say goodbye to page reloads. Master client-side routing with BrowserRouter, Routes, and Link in SPAs.

App.jsx
1 / 10
12345
🧭

Tutor:React Router allows you to build single-page applications (SPAs) with navigation without page refreshes. Let's learn the fundamental components.


Skill Matrix

UNLOCK NODES BY LEARNING ROUTER CONCEPTS.

The Wrapper

<BrowserRouter> uses the HTML5 history API to manage your location. It goes at the top level of your app tree.

System Check

Where should BrowserRouter typically be placed?


Community Holo-Net

Showcase Your Routing

ACTIVE

Built a complex SPA routing structure? Share your setups and nested routes.

React Router & Navigation

Author

Pascual Vila

Frontend Instructor // Code Syllabus

React Router allows us to build Single Page Applications. Instead of sending requests to the server for new HTML pages, the router dynamically swaps components based on the URL.

BrowserRouter

The <BrowserRouter> component keeps your UI in sync with the browser's URL using the HTML5 History API. It must be at the highest level of your routing setup, usually wrapping your entire app.

Routes and Route

The <Routes> component (which replaced Switch in v6) looks through all its child <Route> elements and renders the one that best matches the current URL. You provide a path (like "/about") and an element (the React component).

Link vs a Tag

We never use an <a href="..."> tag for internal routing. It triggers a full page refresh, losing state! Instead, we use <Link to="..."> to intercept the click and update the URL seamlessly.

View Routing History (v5 vs v6)+

In React Router version 5, we used <Switch> instead of <Routes>. Switch rendered the FIRST route that matched, which meant order mattered significantly. Routes in v6 uses a smart ranking algorithm, finding the best exact match regardless of definition order. Also, Route components in v6 use the element prop instead of component or render props.

Router Glossary

BrowserRouter

The main wrapper that uses HTML5 history API to keep your UI in sync with the URL.

snippet.jsx

Routes

Replaced 'Switch' in v6. It groups all routes together and renders the single best matching route.

snippet.jsx

Route

Defines a mapping between a specific URL path and the React element that should render when visited.

snippet.jsx

Link

Navigates around your application without triggering a full browser refresh.

snippet.jsx

useParams

A hook that returns an object of key/value pairs from the current URL's dynamic parameters.

snippet.jsx

useNavigate

A hook to programmatically navigate the user (e.g., after a form submission).

snippet.jsx