State Across Views
Part of the Routing and State section of Coddy's Vue journey. Lesson 41 of 55.
A routed component can unmount while a Pinia store continues to exist in the application. This is useful for selections that belong to a workflow rather than one screen. Each view reads the same store instead of recreating local copies.
// Picker.vue and Summary.vue each call this accessor:
const basket=useBasketStore();
// Picker changes basket selections through actions.
// Summary reads the same selections after navigation.This persistence lasts for the current app instance. It does not imply storage across reloads or another browser tab. Keep ownership deliberate: a view-local note can reset when the view unmounts, while a committed selection in the store survives route changes.
Challenge
MediumUse one Pinia club store across the List and Saved routes. The supplied Toggle save buttons toggle the matching club, and Saved shows only saved records plus their count in p#count. Navigate away and back without losing saved state. The route components may unmount; the store remains owned by the installed Pinia instance.
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 Routes6Route Policies
Redirecting Old PathsUnmatched PathsRoute MetadataCancelling NavigationRecap: Club Destinations9Shared Routed State
State Across ViewsRoute-Selected Store RecordsQuery and Store FiltersDraft and Commit OwnershipRecap: Reading Queue