vue路由爬坑(一)

我先在其他文件定义了一个路由数组,如下:

const adminRouter = [
    {path:"/admin_index",name:'后台管理',component:resolve => require(['./pages/index'], resolve),},
    {path:'/a_people',name:'人员管理',component:resolve => require(['./pages/a_people'], resolve),}
]
export default adminRouter;

然后再总的路由页面引入

import Vue from 'vue'
import VueRouter from 'vue-router';
import  adminRouter from '../his_admin/router.js'
Vue.use(VueRouter)

let constantRouterMap = [
    {path:"/",name:'首页',component:resolve => require(['../pages/PC_index'], resolve),}
]
constantRouterMap.concat(adminRouter)
// console.log(constantRouterMap.concat(adminRouter))
export default new VueRouter({
    mode: 'history',
    base:__dirname,
    routes:constantRouterMap,
})

此时当我导航到/admin_index页面,页面地址栏变了,但页面没有渲染出来;
修改为以下方法可以正常使用

let currentRouterMap = [
    {path:"/",name:'首页',component:resolve => require(['../pages/PC_index'], resolve),}
];

const Routes = currentRouterMap.concat(adminRouter)
// console.log(constantRouterMap.concat(adminRouter))
export default new VueRouter({
    mode: 'history',
    base:__dirname,
    routes:Routes,
})

或者直接修改为

let currentRouterMap = [
    {path:"/",name:'首页',component:resolve => require(['../pages/PC_index'], resolve),}
];
export default new VueRouter({
    mode: 'history',
    base:__dirname,
    routes:currentRouterMap.concat(adminRouter),
})

你可能感兴趣的:(vue路由爬坑(一))