cord8006
cord8006
Explore posts from servers
NNuxt
Created by cord8006 on 5/28/2024 in #❓・help
How to restore the state of a page when navigated from a certain page?
I have a nav bar with links [products, about, contact us, login]. Every link leads to a corresponding page. The /products page shows all the products (product cards) and also has a filter panel that helps to sort and show specific products. When I click on a product card I go to a /product/[id] page where I can read more about a certain product. The page also has a "back to all products" button (actually a nuxt link). What I need is to restore all filter values (i.e. state of the page) when I come back to /products page from the /product/[id] page. But if I came to the /products page via navbar link or from somewhere else, I want all the filters to have default values. I don't like the idea of using query params to store the filter values in url. Also I failed with route middleware which tells the previous route and use pinia store values as filter values if the previous page was /product/[id]. In React I can pass state via routes but Vue/Nuxt seems to not have this feature. So how do I solve my problem?
6 replies