首页 > 其他 > 详细

Vue-大型项目下路由的模块拆分

时间:2021-05-12 14:48:51      阅读:31      评论:0      收藏:0      [点我收藏+]

一、项目的结构

技术分享图片

 

 

 

 二、导出创建的路由对象

技术分享图片

 

 

三、将导出的路由对象全部集合在一起

技术分享图片

 

 

四、在主的index.js文件中导入数据

import { module } from ‘./module/index.js‘
import vue from ‘vue‘

// vue跳转相同路径报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: ‘/‘,
    meta: { title: ‘布局‘},
    name: ‘layout‘,
    component: () => import(‘@/layout/Index‘),
    children: [
      {
        path: ‘/index‘,
        meta: { title: ‘首页‘},
        component: () => import(‘@/views/demo/index/Index‘)
      },
      {
        path: ‘/userInfo‘,
        meta: { title: ‘个人信息‘, isMenu: false},
        component: SANHUI.UserInfo
      },
      {
        path: ‘/405‘,
        meta: { title: ‘405‘, isLogin: false},
        component: SANHUI.Error405
      },
      ...module
    ]
  },
  {
    path: ‘/login‘,
    meta: { title: ‘登录‘, isLogin: false},
    component: SANHUI.Login
  },
  {
    path: ‘*‘,
    meta: { title: ‘404‘, isLogin: false},
    component: SANHUI.Error404
  }
]
const router new VueRouter({
  // mode: ‘history‘,
  // base: process.env.BASE_URL,
  routes
})
// 路由守卫
router.beforeEach((to, from, next) => {
  vue.prototype.$beforeRouter(to, from, next, process.env, Vue)
})

export default router

 

Vue-大型项目下路由的模块拆分

原文:https://www.cnblogs.com/zhilili/p/14759208.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!