How can I use 'useStore' in router-guard #1216
Answered
by
posva
Bacuuu
asked this question in
Help and Questions
-
what I want what is the problem
I have installed pinia,I don't how to resolve this problem. code is here! // main.ts
import router from './router'
app
.use(createPinia())
.use(router)
.mount('#app') // router/index.ts
const router = createRouter({
history: createWebHashHistory(),
routes,
})
guard(router)
export default router // function guard
export default function (router:Router) {
const store = useDialogStore()
// console.log(store)
router.beforeEach((to, from) => {
if (to.meta.requireAuth && !existToken()) {
return {
path: '/login',
}
}
})
} |
Beta Was this translation helpful? Give feedback.
Answered by
posva
Apr 9, 2022
Replies: 1 comment 1 reply
-
Move the iseDialogStore within the navigation guard, before the if (to.meta.requiresAuth |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Bacuuu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Move the iseDialogStore within the navigation guard, before the if (to.meta.requiresAuth