2024-08-13 12:13:29 +08:00
|
|
|
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) {
|
2024-09-12 09:02:34 +08:00
|
|
|
return originalPush.call(this, location).catch((err) => err)
|
2024-08-13 12:13:29 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-12 09:02:34 +08:00
|
|
|
const Layout = () => import('@/views/layout')
|
|
|
|
|
const Home = () => import('@/views/Home/index')
|
|
|
|
|
const Login = () => import('@/views/Login/index')
|
2024-08-13 12:13:29 +08:00
|
|
|
const routes = [
|
|
|
|
|
{
|
|
|
|
|
path: '/',
|
|
|
|
|
redirect: '/Layout',
|
|
|
|
|
},
|
2024-12-05 11:16:37 +08:00
|
|
|
{
|
|
|
|
|
path: '/bigScrap/home-new',
|
|
|
|
|
name: 'home-new',
|
|
|
|
|
component: () => import('@/views/newHome/index.vue'),
|
|
|
|
|
},
|
2024-08-13 12:13:29 +08:00
|
|
|
{
|
|
|
|
|
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: '登录',
|
2024-09-12 09:02:34 +08:00
|
|
|
requireLoginAuth: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-12-05 11:16:37 +08:00
|
|
|
|
2024-09-12 09:02:34 +08:00
|
|
|
],
|
2024-08-13 12:13:29 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '*',
|
|
|
|
|
redirect: '/Layout',
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
const router = new Router({
|
|
|
|
|
mode: 'history',
|
|
|
|
|
routes,
|
2024-12-05 11:16:37 +08:00
|
|
|
base: '',
|
2024-08-13 12:13:29 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.beforeEach(async (to, from, next) => {
|
|
|
|
|
if (to.path === '/login/index') {
|
2024-09-12 09:02:34 +08:00
|
|
|
return next()
|
2024-08-13 12:13:29 +08:00
|
|
|
}
|
2024-09-12 09:02:34 +08:00
|
|
|
const token = localStorage.getItem('token')
|
2024-08-13 12:13:29 +08:00
|
|
|
if (!token) {
|
2024-12-05 11:16:37 +08:00
|
|
|
next('/login/index') // 跳转到登录页
|
2024-08-13 12:13:29 +08:00
|
|
|
} else {
|
2024-09-12 09:02:34 +08:00
|
|
|
next() // 放行
|
2024-08-13 12:13:29 +08:00
|
|
|
}
|
2024-09-12 09:02:34 +08:00
|
|
|
})
|
2024-08-13 12:13:29 +08:00
|
|
|
|
|
|
|
|
// if (to.matched.some(r => r.meta.requireLoginAuth)) {
|
|
|
|
|
// next();
|
|
|
|
|
// } else {
|
|
|
|
|
// next();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
export default router
|