cnbmai-ui-doc/src/router/index.js
2022-12-16 10:10:18 +08:00

140 lines
2.7 KiB
JavaScript

import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '@/store'
Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch((err) => err)
}
import Layout from '@/layout'
/**
* hidden: true if set true, item will not show in the top menuModule(default is false)
*/
export const routes = [
{
path: '/home',
component: Layout,
name: 'home',
meta: {
title: '首页'
},
children: [
{
path: 'introduce',
name: 'introduce',
meta: {
title: '介绍'
},
component: () => import('../views/home/introduce')
}
]
},
{
path: '/table',
component: Layout,
name: 'table',
meta: {
title: '表格'
},
children: [
{
path: 'singleHead',
name: 'singleHead',
meta: {
title: '单表头'
},
component: () => import('../views/table/singleHead')
},
{
path: 'multiLevelHead',
name: 'multiLevelHead',
meta: {
title: '多级表头'
},
component: () => import('../views/table/multiLevelHead')
},
{
path: 'canBeEntered',
name: 'canBeEntered',
meta: {
title: '可输入型'
},
component: () => import('../views/table/canBeEntered')
},
{
path: 'paginationShow',
name: 'paginationShow',
meta: {
title: '分页'
},
component: () => import('../views/table/pagination')
}
]
},
{
path: '/searchBar',
component: Layout,
name: 'searchBar',
meta: {
title: '搜索'
},
children: [
{
path: 'searchBar',
name: 'searchBar',
meta: {
title: '搜索'
},
component: () => import('../views/searchBar/searchBar')
}
]
},
{
path: '/dialog',
component: Layout,
name: 'dialog',
meta: {
title: '对话框'
},
children: [
{
path: 'dialogPage',
name: 'dialogPage',
meta: {
title: '对话框'
},
component: () => import('../views/dialog/dialogPage')
}
]
},
{ path: '*', redirect: '/home/introduce', hidden: true }
]
const router = new VueRouter({
mode: 'hash',
base: process.env.BASE_URL,
routes
})
router.beforeEach((to, from, next) => {
if (to.path === '/login') {
next()
} else {
if (to.matched[0]) {
const activeBox = {
activeModule: to.matched[0].name,
activeMenu: to.matched[1].name
}
store.dispatch('menu/setActiveModule', activeBox)
next()
}
}
})
export default router