Skip to content

Can not use store in router.beforeEach #723

Closed Answered by indyzz
rhinonan asked this question in Help and Questions
Discussion options

You must be logged in to vote

I'm pretty sure that the problem you're running into is that when you export the function as

export default createRouter();

The function will run on import and since this happens before the Pinia instance has been created it won't work. The second example o n the "Stores outside of components"-section have an example of a structure that might work better

https://pinia.esm.dev/core-concepts/outside-component-usage.html#single-page-applications

Replies: 6 comments 14 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@posva
Comment options

@wangfengyuan
Comment options

Comment options

You must be logged in to vote
2 replies
@floydjones1
Comment options

@indyzz
Comment options

Comment options

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

Answer selected by posva
Comment options

You must be logged in to vote
6 replies
@sylvainpolletvillard
Comment options

@llbarr1
Comment options

@legend0858
Comment options

@rachitpant
Comment options

@dudintv
Comment options

Comment options

You must be logged in to vote
3 replies
@devemrekaratas
Comment options

@do-adams
Comment options

@iwusong
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Converted from issue

This discussion was converted from issue #722 on October 14, 2021 14:33.