mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-07 05:31:24 +00:00
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:
committed by
GitHub
parent
414531524c
commit
f623cd0179
16
resources/scripts/router/index.js
vendored
16
resources/scripts/router/index.js
vendored
@@ -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' }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user