If you’ve ever built a React app and thought,
“Why does my page reload every time I click a link?”
you’re not alone.
That moment is usually where things start getting interesting…
and where something like Browser Router quietly steps in to save your user experience.
And if you’re following along with my series
"Mastering React Hooks Together",
this is the 3rd episode
and trust me, this piece matters more than it looks.
Because before jumping into hooks like useNavigate, there’s something fundamental you need to understand first… and that’s exactly what we’re unpacking here.
Let’s break it down in a way that actually makes sense — no robotic explanations, no unnecessary jargon. Just real understanding.
So… Why Does Browser Router Even Exist?
React is built for speed and smoothness. It updates parts of the page without refreshing the whole thing. But here’s the catch:
👉 Browsers don’t work that way by default.
When you click a normal link (<a href="/about">), the browser reloads the entire page. That means:
- Your app resets
- State is lost
- It feels slow and clunky
Not exactly the “modern app” experience we want.
This is where Browser Router comes in — it lets your React app behave like a real single-page application (SPA), where navigation feels instant.
But how does it actually pull that off?
What is Browser Router (Official + Simple)
Official idea:
Browser Router is a routing component that uses the browser’s History API to keep your UI in sync with the URL.
Now in plain English:
👉 It watches the URL and decides what component to show — without refreshing the page.
Think of it like a smart traffic controller:
- URL changes → Browser Router reacts → React renders the right component
No reloads. No flicker. Just smooth transitions.
And once you see it in action, you’ll realize it’s not just “nice to have” — it’s essential.
The Problem It Actually Solves
Let’s paint a quick picture.
Imagine you’re building a simple app:
- Home page
- About page
- Contact page
Without routing, you’d either:
- Reload the page every time (bad UX), or
- Manually control everything with state (messy and hard to scale)
Neither feels right.
Browser Router solves this by:
- Keeping the UI and URL in sync
- Letting users bookmark/share links
- Enabling back/forward navigation
- Avoiding full page reloads
Basically, it gives your React app a real navigation system.
And once navigation is handled cleanly, the next natural question becomes…
How Do You Actually Use Browser Router?
Let’s keep this practical — but this time, not just what to write… also why each line exists, so nothing feels like magic.
Step 1: Install React Router
npm install react-router-dom
- This installs the routing library your app doesn’t have by default. React itself doesn’t handle routing — so you’re bringing in the tool that will.
Step 2: Wrap Your App
import { BrowserRouter } from "react-router-dom";
function App() {
return (
<BrowserRouter>
{/* Your routes go here */}
</BrowserRouter>
);
}
Let’s break this down:
import { BrowserRouter }...
👉 You’re importing the component that enables routing using the browser’s URL.<BrowserRouter>
👉 This is the engine of your routing system.
It listens to URL changes and provides routing context to everything inside it.{/* Your routes go here */}
👉 This is where your app’s pages will live — but they only work because they’re inside Browser Router.
So at this point:
👉 Your app is now aware of URLs.
But it still doesn’t know what to render for each URL… and that leads us to the next step.
Step 3: Define Routes
import { Routes, Route } from "react-router-dom";
function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
</Routes>
</BrowserRouter>
);
}
Here:
import { Routes, Route }...
👉 These help you define which component should show for which URL.<Routes>
👉 Think of this as a container that holds all your route rules.<Route path="/" element={<Home />} />
👉 When the URL is/, React renders theHomecomponent.<Route path="/about" element={<About />} />
👉 When the URL is/about, React switches to theAboutcomponent.
Now something important just happened:
👉 Your app can now map URLs to UI.
But how does the user actually move between these URLs without reloading?
Step 4: Navigate Without Reloading
import { Link } from "react-router-dom";
<Link to="/about">Go to About</Link>
Let’s unpack it:
import { Link }...
👉 This replaces the normal<a>tag in React apps.<Link to="/about">
👉 Instead of reloading the page, it updates the URL internally.Go to About
👉 What the user clicks.
So when clicked:
👉 URL changes → Browser Router detects it → सही component renders → no reload
And now everything connects:
- Browser Router watches the URL
- Routes decide what to render
- Link changes the URL smoothly
That’s the full loop.
And once this loop clicks in your head, navigation stops feeling confusing… and starts feeling powerful.
When Should You Use Browser Router?
Short answer?
👉 Almost always — if you're building a web app.
But let’s be specific.
Use it when:
- You have multiple pages/views
- You want clean URLs
- You care about user experience
- You don’t want page reloads
Avoid it only if:
- Your app is extremely small (like a single static view)
- Or you’re using a different routing strategy (like hash-based routing for legacy setups)
Otherwise, Browser Router is your go-to.
And once navigation is set up, clicking links is just one part of the story…
Is Browser Router Just for useNavigate?
Not exactly — but it makes it possible.
Browser Router is the foundation.
Hooks like useNavigate are tools built on top of it.
Without Browser Router:
👉 useNavigate won’t work.
With Browser Router:
👉 You can programmatically move users around your app.
And this is exactly why understanding Browser Router comes before learning useNavigate.
Because:
-
useNavigatedepends on routing context - That context is created by Browser Router
- Without it, navigation logic simply has nowhere to run
So if you jump straight into useNavigate without this base, things will feel confusing or even break entirely.
Example:
import { useNavigate } from "react-router-dom";
function Home() {
const navigate = useNavigate();
return (
<button onClick={() => navigate("/about")}>
Go to About
</button>
);
}
This is where things shift from “basic routing” to “controlled user flow.”
Now you’re not just linking pages — you’re guiding users.
Bringing It All Together
Browser Router isn’t just another library piece you install and forget.
It’s what transforms your React app from:
👉 A collection of components
into
👉 A real, navigable application
It:
- Eliminates full page reloads
- Keeps URLs meaningful
- Improves performance and UX
- Enables powerful navigation patterns
And once you start using it, you’ll wonder how you ever built apps without it.
One Last Thought
If you’re continuing this journey with
“Mastering React Hooks Together”,
this 3rd episode sets the stage for everything that comes next.
Because when we step into hooks like useNavigate, you won’t just memorize syntax — you’ll actually understand what’s happening under the hood.
And that’s the difference between using React… and mastering it.
Top comments (0)