Missing Route Records
Part of the Routing and State section of Coddy's Vue journey. Lesson 14 of 55.
Matching a route pattern does not guarantee that its referenced data exists. A path such as /books/unknown can match /books/:slug even when the local catalog has no corresponding record.
const book = computed(() => catalog[route.params.slug]);
// <h2 v-if="book">{{ book.title }}</h2>
// <p v-else>Book not found</p>Check the lookup result before reading its fields. Render a useful fallback while retaining the current location, then let the reactive lookup recover when the user chooses a valid record. This handles missing data inside a matched route; a route that matches no pattern is a separate case covered later.
Challenge
MediumThe route pattern matches any exhibit slug, but the supplied data only contains forest and river. In Exhibit.vue, derive the current title. For known records render h2#view; otherwise render only p#missing with Exhibit not found. Recover correctly when navigation returns from an unknown slug to a known one.
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 Reservations3Dynamic Routes
Path ParametersReactive Route SelectionRoute Parameters as PropsMissing Route RecordsRecap: Equipment Routes