React Navigation with Link

In the last lesson, React Nested Routes, you built sections with shared layouts. This lesson shows you the Link component, React Router’s way to move between pages with a click and no reload.

🤔 Why not just use an anchor tag?

Here’s the pain. The plain HTML <a> tag does work, but it does the wrong thing for an SPA.

  • A normal <a href="/about"> makes the browser ask the server for a whole new page.
  • The screen goes blank and reloads, which is slow and feels clunky.
  • It throws away your app’s current state and starts fresh every time.
  • You lose the whole point of a single-page app, which is instant page changes.

So you need a way to change pages that updates the URL and swaps the component, without a reload. That’s exactly what Link is for.

Link looks and feels like a normal link, but it navigates the React Router way. Instead of href, it uses a to prop.

import { Link } from "react-router-dom";
function Navbar() {
return (
<nav>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
<Link to="/contact">Contact</Link>
</nav>
);
}

Read the difference from a normal link.

  • We import Link from react-router-dom.
  • Instead of href, Link uses to for the path, like to="/about".
  • Clicking it changes the URL and shows the matching route, with no page reload.
  • To the user it looks exactly like a normal link, it’s just faster.

to instead of href

The one thing to remember: Link uses to, not href. So it’s <Link to="/about">, not <Link href="/about">. Everything else feels like a normal link.

It helps to see what Link actually does compared to <a>, so you trust why it’s faster.

  • A plain <a> triggers a full request to the server and a fresh page load.
  • Link stops that default behavior and tells React Router to handle it in the browser.
  • React Router updates the URL and swaps to the matching component, keeping the app alive.
  • The browser’s back and forward buttons still work, because React Router updates the history.

So Link gives you a real, clickable, shareable link, but it navigates instantly instead of reloading. Best of both.

Link works great with the route parameters you learned. You build the to path with the value you want, like a user’s id.

import { Link } from "react-router-dom";
function UserList({ users }) {
return (
<ul>
{users.map((user) => (
<li key={user.id}>
<Link to={`/users/${user.id}`}>{user.name}</Link>
</li>
))}
</ul>
);
}

See how the link is built.

  • We map over users and make a Link for each one.
  • The to uses a template string, `/users/${user.id}`, so each link points to that user.
  • Clicking “Alex” might go to /users/1, which your :id route then handles.
  • So the list of names becomes a list of links straight to each profile page.

So Link and route parameters work as a team: build the path with the id, and the parameter route reads it on the other side.

⚠️ Common Mistakes

The most common mistake is using a plain <a> tag instead of Link for internal pages, causing a full reload.

// ❌ a plain anchor reloads the whole page, losing SPA speed
<a href="/about">About</a>
// ✅ Link navigates with no reload
<Link to="/about">About</Link>

Keep these in mind.

  • Don’t use <a> for pages inside your app. It reloads and kills the SPA feel. Use Link.
  • Don’t write href on a Link. It uses to.
  • Do use a normal <a> for external sites, like linking to another website. Link is only for routes inside your app.

Anchor for external, Link for internal

Use Link for pages inside your own app. For a link to a different website, like https://google.com, a plain <a href> is correct, because that really is leaving your app.

✅ Best Practices

A few habits for navigation.

  • Use Link for every internal page change, so navigation stays instant.
  • Remember to for the path, not href.
  • Build dynamic links with template strings, like to={`/users/${id}`}.
  • Keep using a plain <a> only for external links that leave your app.

Links can be styled freely

A Link renders as a normal anchor in the page, so you can style it with CSS just like any link. It only changes how the click is handled, not how it looks.

🧩 What You’ve Learned

  • ✅ A plain <a> reloads the whole page, which throws away the speed of a single-page app
  • Link from React Router changes pages with no reload, keeping the app fast
  • Link uses the to prop for the path, not href
  • ✅ It updates the URL and shows the matching route, and the back/forward buttons still work
  • ✅ Build dynamic links with template strings, like to={`/users/${id}`}
  • ✅ Use Link for internal pages, but a normal <a> for external websites

Check Your Knowledge

Test what you learned. Pick an answer for each question, then click Check.

  1. 1

    Why use Link instead of a plain anchor tag for internal pages?

    Why: A plain <a> reloads the whole page from the server. Link changes the URL and swaps the component in the browser with no reload, which is the point of an SPA.

  2. 2

    Which prop does Link use for the path?

    Why: Link uses the to prop, like <Link to='/about'>. Writing href on a Link is a common mistake.

  3. 3

    How do you build a Link to a dynamic route like a user profile?

    Why: Build the path with the actual value using a template string, so to={`/users/${user.id}`} points to that specific user's page.

  4. 4

    When is a plain anchor tag still the right choice?

    Why: Link is for internal routes. For an external site like https://google.com, a normal <a href> is correct, because you really are leaving your app.

🚀 What’s Next?

Now your users can click to move between pages instantly. But there’s a nicer link for navigation menus, one that knows which page is active and can highlight itself. Next you’ll learn NavLink.

React Navigation with NavLink

Share & Connect