Redirect to route on value.
I need to integrate with an exisiting system and that will pass information using local store. Because I am using Pinia I am reading the local stor and hydrating Pinia and would then like to redirect to the appropiate route based on a value in local store. I am using CSR
const testStore = useTestStore();
// Read from localstorage
const testToken = ref(getItem('testToken'));
// Save it in Pinia
testStore.setTestToken(testToken);
const targetRoute = ref(getItem('target'));
// How can I redirect to a route based on the contants of target ?
2 Replies
You can use navigateTo() to programatically route to another route: https://nuxt.com/docs/api/utils/navigate-to
"Because I am using Pinia I am reading the local store and hydrating Pinia" have you heard of pinia-persistentstate: https://github.com/prazdevs/pinia-plugin-persistedstate
It auto-hydrates and saves a Pinia store for you if wanted.
GitHub
GitHub - prazdevs/pinia-plugin-persistedstate: 🍍 Configurable persi...
🍍 Configurable persistence and rehydration of Pinia stores. - prazdevs/pinia-plugin-persistedstate