import Vue from 'vue'
|
import Router from 'vue-router'
|
|
Vue.use(Router)
|
|
/* Layout */
|
import Layout from '@/layout'
|
|
import demo_router from './demo_router'
|
import system_router from './system_router'
|
import op_router from './op_router'
|
import agreement_router from './agreement_router'
|
|
/**
|
* 注:子菜单只出现在路线子时。长度> = 1
|
* 详细信息见: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
|
*
|
* hidden: true 项目将不会在侧边栏显示(默认为false)
|
* alwaysShow: true 如果设置为true,将始终显示根菜单
|
* 如果没有设置alwaysShow,当项目有多个子路径时,
|
* 它将变成嵌套模式,否则不会显示根菜单
|
* redirect: noRedirect 如果设置了noRedirect将不会在面包屑中重定向
|
* name:'router-name' <keep-alive>使用该名称(必须设置!!)
|
* meta : {
|
roles: ['admin','editor'] 控制页面角色(可以设置多个角色)s)
|
title: 'title' 在侧边栏和面包屑中显示的名称(推荐设置)
|
icon: 'svg-name'/'el-icon-x' 图标显示在侧边栏
|
breadcrumb: false 项目将隐藏在breadcrumb中(默认为true)
|
activeMenu: '/example/list' 如果设置路径,侧边栏将突出显示您设置的路径
|
}
|
*/
|
|
/**
|
* constantRoutes
|
* 没有权限要求的基本页面
|
* 所有角色都可以访问
|
*/
|
export const constantRoutes = [
|
{
|
path: '/login',
|
component: () => import('@/pages/login/index'),
|
hidden: true
|
},
|
|
{
|
path: '/404',
|
component: () => import('@/pages/404'),
|
hidden: true
|
},
|
|
{
|
path: '/',
|
component: Layout,
|
redirect: '/dashboard',
|
children: [{
|
path: 'dashboard',
|
name: '首页',
|
component: () => import('@/pages/dashboard/index'),
|
meta: { title: '首页', icon: 'dashboard' }
|
}]
|
},
|
|
system_router,
|
demo_router,
|
agreement_router,
|
|
{
|
path: 'external-link',
|
component: Layout,
|
children: [
|
{
|
path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
|
meta: { title: '外链', icon: 'link' },
|
auth: 'external_link'
|
}
|
]
|
},
|
|
// {
|
// path: '/demo',
|
// component: Layout,
|
// children: [
|
// {
|
// path: '/demo',
|
// component: () => import('@/pages/demo/demo'), // Parent router-view
|
// name: 'demo',
|
// meta: { title: 'demo', icon: 'example' }
|
// }
|
// ]
|
// },
|
|
op_router,
|
|
// 404 page must be placed at the end !!!
|
{ path: '*', redirect: '/404', hidden: true }
|
]
|
|
const createRouter = () => new Router({
|
// mode: 'history', // require service support
|
scrollBehavior: () => ({ y: 0 }),
|
routes: constantRoutes
|
})
|
|
const router = createRouter()
|
|
// 守卫,处理keepAlive周期,用isBack标记是否属于从属页面后退
|
router.beforeEach(function(to, from, next) {
|
// 判断是否从从属页面后退
|
if (to.meta.keepAlive && from.meta.activeMenu === to.path) {
|
to.meta.isBack = true
|
} else {
|
to.meta.isBack = false
|
}
|
next(true)
|
})
|
|
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
|
export function resetRouter() {
|
const newRouter = createRouter()
|
router.matcher = newRouter.matcher // reset router
|
}
|
|
export default router
|