Menu
CoddyTech

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 icon

Challenge

Medium

Use 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>
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