devicesmgt/sgzb-screen/src/router/index.js

90 lines
1.7 KiB
JavaScript

import Vue from 'vue'
import Router from 'vue-router'
import store from '@/store'
Vue.use(Router)
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
const Layout = () => import('@/views/layout');
const Home = () => import('@/views/Home/index');
const Login = () => import('@/views/Login/index');
const routes = [
{
path: '/',
redirect: '/Layout',
},
{
path: '/Layout',
component: Layout,
name: 'Layout',
redirect: '/Home/index',
meta: {
title: '南方电网',
requireLoginAuth: true,
},
// path: '/Layout',
// component: Layout,
// name: 'Layout',
// redirect: '/Login/index',
// meta: {
// title: '南方电网',
// requireLoginAuth: true,
// },
children: [
{
path: '/Home/index',
component: Home,
name: 'Home',
meta: {
title: '首页',
requireLoginAuth: true,
},
},
{
path: '/Login/index',
component: Login,
name: 'Login',
meta: {
title: '登录',
requireLoginAuth: true
}
}
]
},
{
path: '*',
redirect: '/Layout',
},
]
const router = new Router({
mode: 'history',
routes,
})
router.beforeEach(async (to, from, next) => {
if (to.path === '/login/index') {
return next();
}
const token = localStorage.getItem('token');
if (!token) {
next('/login/index'); // 跳转到登录页
} else {
next(); // 放行
}
});
// if (to.matched.some(r => r.meta.requireLoginAuth)) {
// next();
// } else {
// next();
// }
export default router