zoukankan      html  css  js  c++  java
  • Vue-大型项目下路由的模块拆分

    一、项目的结构

     二、导出创建的路由对象

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

    四、在主的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
  • 相关阅读:
    java线程管理
    java进程间通信
    Possible multiple enumeration of IEnumerable
    Adding Search
    Working with SQL Server LocalDB
    ASP.NET Razor
    ASP.NET Razor
    modelstate.isvalid false
    Razor Intro
    open Command window here
  • 原文地址:https://www.cnblogs.com/zhilili/p/14759208.html
Copyright © 2011-2022 走看看