success news hot

This commit is contained in:
2023-12-23 18:01:51 +08:00
parent 46905ed6f1
commit 2faf2db922
17 changed files with 584 additions and 260 deletions

View File

@@ -63,7 +63,7 @@ const routes = [
{
path: '/admin',
name: '/admin',
component: personalHomePage
component: personalHomePage,
},
{
path: '/system',
@@ -138,5 +138,40 @@ const router = new VueRouter({
mode: 'history',
routes
})
// // 导航守卫:使用 router.beforeEach 注册一个全局前置守卫,判断用户是否登陆
// router.beforeEach((to, from, next) => {
// if (to.path === '/home') {
// next();
// } else {
// let token = localStorage.getItem('Authorization');
// if (token === null || token === '') {
// next('/home');
// } else {
// next();
// }
// }
// });
// 全局路由构造函数,判断是否登录和要跳转到页面
router.beforeEach((to, from, next) => {
if (to.matched.some(m => m.meta.requiresAuth)) { // 需要登录
if(window.localStorage.Authorization && window.localStorage.isLogin === '1'){
next()
} else if (to.path !== '/home') {
let token = localStorage.getItem('Authorization');
if (token === 'null' || token === '' || token === undefined){
next({path: '/home'})
// Toast({ message: '检测到您还未登录,请登录后操作!', duration: 1500 })
Vue.prototype.$notify.error({
title: '权限不够',
message: "请先登录!",
offset: 0
});
}
} else {
next()
}
} else { // 不需要登录
next()
}
})
export default router