12345678910111213141516171819202122232425262728293031323334353637 |
- import { fn_logout } from '@/utils'
- const paths = ['/login']
- export function createRouterGuards(router, systemStore) {
- const routes = router.getRoutes()
- // 前置
- router.beforeEach(async (to, from, next) => {
- // 如果用户进入了登录页面就相当于退出
- if (paths.includes(to.path)) {
-
- fn_logout()
- return next()
- }
- // 验证菜单
- const menus = systemStore.getMenus
- if(menus.length == 0) return next('/login')
- if (to.matched.length === 0) {
- return next('/errors')
- }
-
- next()
- })
- router.afterEach((to, _, next) => {
- // const Loading = window['$loading']
- // setTitle(to.meta.title as string | undefined)
- // Loading && Loading.submit-success()
- })
- // 错误
- router.onError(error => {
- console.log(error, '路由错误')
- })
- }
|