Upgrade vue-router from v4 to v5 (#598)

- Migrate beforeEach navigation guard from next() callback to return-based
  API, preparing for vue-router v6 where next() is removed
This commit is contained in:
Darko Gjorgjijoski
2026-04-02 16:47:16 +02:00
committed by GitHub
parent 414531524c
commit f623cd0179
2 changed files with 8 additions and 10 deletions

View File

@@ -17,22 +17,20 @@ const router = createRouter({
routes,
})
router.beforeEach((to, from, next) => {
router.beforeEach((to) => {
const userStore = useUserStore()
const globalStore = useGlobalStore()
let ability = to.meta.ability
const { isAppLoaded } = globalStore
if (ability && isAppLoaded && to.meta.requiresAuth) {
if (userStore.hasAbilities(ability)) {
next()
} else next({ name: 'account.settings' })
if (!userStore.hasAbilities(ability)) {
return { name: 'account.settings' }
}
} else if (to.meta.isOwner && isAppLoaded) {
if (userStore.currentUser.is_owner) {
next()
} else next({ name: 'dashboard' })
} else {
next()
if (!userStore.currentUser.is_owner) {
return { name: 'dashboard' }
}
}
})