Path Parameters
Part of the Routing and State section of Coddy's Vue journey. Lesson 11 of 55.
A colon marks a variable path segment. The record below matches both /books/atlas and /books/poems. The matched segment is available as route.params.slug.
{ path: '/books/:slug', name: 'book', component: Book }
// In Book.vue setup:
const route = useRoute();
// Template: <h2>{{ route.params.slug }}</h2>Use a named location with a params object when building a parameterized link, such as { name: 'book', params: { slug: 'atlas' } }. Parameter keys must match the record names. Ordinary single-segment params are strings, so a numeric-looking id is not automatically a number.
Challenge
MediumDefine a named exhibit route at /exhibits/:slug. In Exhibit.vue, obtain the current route and display Exhibit: followed by its slug in h2#view. Keep the supplied named Moon and Ocean links working for both parameter values.
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