Menu
CoddyTech

Ancestor Navigation State

Part of the Routing and State section of Coddy's Vue journey. Lesson 24 of 55.

A link to a parent record can be active while a descendant is displayed. Active matching includes matched ancestor records with compatible params. Exact-active identifies the destination itself, which is useful for emphasizing the specific current page.

a.router-link-active { color: teal; }
a.router-link-exact-active { font-weight: 700; }

Use the two classes for different purposes rather than assuming every active link is the exact page. A section link can remain colored throughout its children while the current child link is bold. Query values do not determine active-link matching, so query-only filter changes do not usually change these classes.

challenge icon

Challenge

Medium

Style studio navigation so an ancestor link shows active styling on any of its child routes. Set color: rgb(20, 90, 140) on a.router-link-active and font-weight: 700 on a.router-link-exact-active. All anchors otherwise use color: rgb(50, 50, 50) and weight 400. At a child, Overview is active but only that child is exact-active.

Keep the supplied route readout and bootstrap files.

Try it yourself

<!doctype html><html><head><meta charset="UTF-8"><title>Routing practice</title></head><body><div id="app"></div><script type="module" src="./main.js"></script></body></html>
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Routing and State