how to define in svelte.js a global variable over several pages using svelte-router-spa

Viewed 7964

I'm trying to learn svelte and build a card-solution with routing through svelte-router-spa. On each view (index and productdetails) i import my variable basket. This should contain my card-array over the different pages. Unfortunately on every page my array is empty again. How can I define a global var through every page?

thanks for your help.

1 Answers

This sounds like a problem that can be solved using a writable store. Stores (if you don't know) are essentially storage for things such as variables and other data which apply across all your components (if imported from your stores file). The documentation can be found here: https://svelte.dev/tutorial/writable-stores

Related