can I call useRouter()
inside store?
#442
-
Hi, can I call I tried calling Thanks in advance |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Like any function based on pinia.use(() => ({ router })
createApp(App).use(router).use(pinia).mount('#app') And type it with // extensions.d.ts
import 'pinia'
import { Router } from 'vue-router'
declare module 'pinia' {
export interface PiniaCustomProperties {
router: Router
}
} The plugin API is a WIP at #416 |
Beta Was this translation helpful? Give feedback.
Like any function based on
inject()
, you won't be able to use it outside ofsetup()
. With the plugin API you can add a router property to each store:And type it with
The plugin API is a WIP at #416
The ongoing docs are at https://deploy-preview-416--pinia.netlify.app/core-concepts/plugins.html#typescript