async
function
loadAsyncRoutes() {
let userInfo = storage.getItem(
'userInfo'
) || {}
if
(userInfo.token) {
try
{
const { menuList } = await API.getPermissionList()
let routes = utils.generateRoute(menuList)
const modules = import.meta.glob(
'../views/*.vue'
)
console.log(
'views'
,modules)
routes.map(route => {
let url = `../views/${route.name}.vue`
route.component = modules[url];
router.addRoute(
"home"
, route);
})
}
catch
(error) {
}
}
}
loadAsyncRoutes();
/*
function
checkPermission(path) {
let hasPermission = router.getRoutes().filter(route => route.path == path).length;
if
(hasPermission) {
return
true
;
}
else
{
return
false
;
}
}
*/
router.beforeEach(async (to, from, next) => {
if
(to.name) {
if
(router.hasRoute(to.name)) {
document.title = to.meta.title;
next()
}
else
{
next(
'/404'
)
}
}
else
{
await loadAsyncRoutes()
let curRoute = router.getRoutes().filter(item => item.path == to.path)
if
(curRoute?.length) {
document.title = curRoute[0].meta.title;
next({ ...to, replace:
true
})
}
else
{
next(
'/404'
)
}
}
})