4.vue Router路由设置
router=>index.js 设置路由信息
1.路由文件按分组拆分多个
import analysisRouter from './analysisRouter';
import usersRouter from './usersRouter';
import dashboardRouter from './dashboardRouter';
Vue.use(Router)
const routerConfig = {
...analysisRouter,
...usersRouter,
...dashboardRouter,
};
//把拆分的路由请求汇总
const routerList = Object.keys(routerConfig).map(key => routerConfig[key]);
2.修改默认的views目录为pages,存放页面
const routes = routerList.map(item => {
if (item.path.match('pages')){
return {
path: item.path,
name: item.name,
alias: item.path.split('/pages')[1],
//动态加载
component: () => import(`../pages${item.component}`),
beforeEnter: item.beforeEnter || ((to, from, next)=> { next() })
}
} else {
return {
path: item.path,
name: item.name,
component: () => import(`../components${item.component}`),
}
}
})
修改路由为
export default router;