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
MediumStyle 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>This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Routing and State
4Query State
Reading Query ValuesCommitting Search QueriesPreserving Other FiltersNormalizing Query NumbersRecap: Catalog Filters2Navigation Actions
Navigation from HandlersReplacing HistoryHistory TravelCurrent Navigation LinksRecap: Save and Review5Nested Layouts
Parent and Child OutletsDefault Child ViewsRelative Child PathsAncestor Navigation StateRecap: Library Workspace8Store Design
Setup Store StructurePatching Related StateResetting Store StateComposing Related StoresRecap: Trip Pack11Workshop Planner Project
Planner RoutesShared Reservations