use router in pinia #1092
-
how to use in pinia import { useRouter } from "vue-router"; pinia.use(({ store }) => { |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 13 replies
-
Hi, |
Beta Was this translation helpful? Give feedback.
-
I'm using firebase and want to redirect the user to the login page if he/she is not authenticated. I followed the steps above and there is no error. The thing is that I'm using the store as a composable and cannot reach |
Beta Was this translation helpful? Give feedback.
-
Occasionally appears inject() can only be used inside setup() or functional components. |
Beta Was this translation helpful? Give feedback.
Hi,
add router to pinia like that:
const pinia = createPinia() pinia.use(({ store }) => { store.router = markRaw(router) }); app.use(pinia)
then you have access to router in pinia store by the
this
. I don't now why in my case (i use typescript) webstorm don't see this.router but he is there ;) I add @ts-ignore to let phpstorm not complain for now