1
This commit is contained in:
46
admin/src/router/index.js
Normal file
46
admin/src/router/index.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import Vue from "vue";
|
||||
import Router from "vue-router";
|
||||
import iView from "iview";
|
||||
import config from "@/config";
|
||||
|
||||
import { getToken } from "@/libs/util";
|
||||
import routes from "./routers";
|
||||
|
||||
const { homeName } = config;
|
||||
const LOGIN_PAGE_NAME = "login";
|
||||
|
||||
Vue.use(Router);
|
||||
|
||||
const router = new Router({
|
||||
routes,
|
||||
mode: "hash"
|
||||
});
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
const token = getToken();
|
||||
iView.LoadingBar.start();
|
||||
|
||||
if (!token && to.name !== LOGIN_PAGE_NAME) {
|
||||
// 未登录且要跳转的页面不是登录页
|
||||
next({
|
||||
name: LOGIN_PAGE_NAME // 跳转到登录页
|
||||
});
|
||||
} else if (!token && to.name === LOGIN_PAGE_NAME) {
|
||||
// 未登陆且要跳转的页面是登录页
|
||||
next(); // 跳转
|
||||
} else if (token && to.name === LOGIN_PAGE_NAME) {
|
||||
// 已登录且要跳转的页面是登录页
|
||||
next({
|
||||
name: homeName // 跳转到homeName页
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
});
|
||||
|
||||
router.afterEach(to => {
|
||||
iView.LoadingBar.finish();
|
||||
window.scrollTo(0, 0);
|
||||
});
|
||||
|
||||
export default router;
|
||||
18
admin/src/router/routers.js
Normal file
18
admin/src/router/routers.js
Normal file
@@ -0,0 +1,18 @@
|
||||
export default [
|
||||
{
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
component: () => import('@/view/login/login.vue')
|
||||
},
|
||||
{
|
||||
path: '*',
|
||||
name: 'error_401',
|
||||
component: () => import('@/view/error-page/401.vue')
|
||||
},
|
||||
|
||||
{
|
||||
path: '/500',
|
||||
name: 'error_500',
|
||||
component: () => import('@/view/error-page/500.vue')
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user