mirror of
https://github.com/InvoiceShelf/InvoiceShelf.git
synced 2026-04-20 03:34:06 +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
@@ -52,7 +52,7 @@
|
|||||||
"vue": "^3.5",
|
"vue": "^3.5",
|
||||||
"vue-flatpickr-component": "^11.0.5",
|
"vue-flatpickr-component": "^11.0.5",
|
||||||
"vue-i18n": "^11.0.1",
|
"vue-i18n": "^11.0.1",
|
||||||
"vue-router": "^4.5.0",
|
"vue-router": "^5.0.0",
|
||||||
"vuedraggable": "^4.1.0"
|
"vuedraggable": "^4.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
resources/scripts/router/index.js
vendored
16
resources/scripts/router/index.js
vendored
@@ -17,22 +17,20 @@ const router = createRouter({
|
|||||||
routes,
|
routes,
|
||||||
})
|
})
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to) => {
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
const globalStore = useGlobalStore()
|
const globalStore = useGlobalStore()
|
||||||
let ability = to.meta.ability
|
let ability = to.meta.ability
|
||||||
const { isAppLoaded } = globalStore
|
const { isAppLoaded } = globalStore
|
||||||
|
|
||||||
if (ability && isAppLoaded && to.meta.requiresAuth) {
|
if (ability && isAppLoaded && to.meta.requiresAuth) {
|
||||||
if (userStore.hasAbilities(ability)) {
|
if (!userStore.hasAbilities(ability)) {
|
||||||
next()
|
return { name: 'account.settings' }
|
||||||
} else next({ name: 'account.settings' })
|
}
|
||||||
} else if (to.meta.isOwner && isAppLoaded) {
|
} else if (to.meta.isOwner && isAppLoaded) {
|
||||||
if (userStore.currentUser.is_owner) {
|
if (!userStore.currentUser.is_owner) {
|
||||||
next()
|
return { name: 'dashboard' }
|
||||||
} else next({ name: 'dashboard' })
|
}
|
||||||
} else {
|
|
||||||
next()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user