Course contentsShow
← React
Lesson 1841 of 2,39643. RoutingFree lesson

Relative Links in Nested Routes

Using relative Link paths that resolve from the current route location, simplifying navigation in nested structures.

What You'll Learn

You'll learn how to use relative paths in <Link> components to simplify navigation within nested route structures, making your routing code more maintainable and portable.

The Problem with Absolute Paths

When you nest routes deeply, hardcoding absolute paths in every Link becomes tedious and brittle. Imagine you have /dashboard/settings/profile and want to link to /dashboard/settings/account. If you later reorganize and move "settings" elsewhere, you'd need to update every absolute path.

Relative Links: Navigate from Where You Are

React Router lets you use relative paths in Link components—paths that resolve from the current route location rather than from the root. It's like giving directions: instead of saying "go to 123 Main Street from downtown" every time, you say "go one block east" from wherever you currently stand.

// Absolute path (brittle)
<Link to="/dashboard/settings/account">Account</Link>

// Relative path (flexible)
<Link to="account">Account</Link>
<Link to="../profile">Profile</Link>

When you're at /dashboard/settings, the relative path "account" resolves to /dashboard/settings/account. The path "../profile" goes up one level to /dashboard, then down to profile, resolving to /dashboard/profile.

When to Use Relative Links

Use relative paths in components that are part of a nested route structure. Your layout components and child route pages can navigate within their section without knowing the full path hierarchy. This makes them reusable—move the entire route subtree, and the internal links still work.

// Inside /dashboard/settings route
<Link to="profile">Profile</Link>      {/* → /dashboard/settings/profile */}
<Link to="..">Back to Dashboard</Link> {/* → /dashboard */}

Key Takeaway: Relative Link paths resolve from your current route location, letting you write portable navigation code that doesn't break when you restructure your route tree.