component: () =>
import(/* webpackChunkName: "xtgl" */ '@/views/xtgl/gwgl')
路由懒加载:文件的切割,把组件的代码单独打包为独立的JS => 对页面第一加载的性能体验有很大的帮助
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch(err => err)
}
const routes = [
{ path: '/', redirect: '/login' },
{
path: '/login',
component: () => import('@/views/login/index')
},
{
path: '/404',
component: () => import('@/views/error/Error404'),
},
{
path: '/home',
component: () => import('@/views/Home'),
children: [
{
path: '/xtgl/gwgl',
component: () =>
import(/* webpackChunkName: "xtgl" */ '@/views/xtgl/gwgl')
}
]
},
{
path: '*', // 页面不存在的情况下会跳到404页面
redirect: '/404',
}
]
const router = new VueRouter({
routes
})
export default router