Skip to content

Can't use store in router.beforeEach. State not updated #1083

Discussion options

You must be logged in to vote

Ok, so finally i was able to fix it. For whoever might run into the same problem:
The issue was that i was defining the navigation guard within createApp, but for getting the store state from SSR i waited to do that after router.isReady. That way router worked with another store state then the app. so getting the store state from SSR needs to be done before calling router.isReady(). Then everything works like a charme.

Fixed version:

main.ts

import { createSSRApp, markRaw } from 'vue';
import { createRouter } from './router';
import { createPinia } from 'pinia';
import App from '/@/App.vue';
import { useLocaleStore } from './store/locale';

// SSR requires a fresh app instance per request…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@awacode21
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by awacode21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant