当前位置: 首页 > Web前端 > vue.js

vue路由优化

时间:2023-03-31 20:00:46 vue.js

很多小伙伴直接在路由文件中写路由,这样会导致路由文件往往有几千行,整个文件会很繁琐。我们可以新建一个路由文件夹,importexportdefault{path:'/index',name:'index',component:()=>import('../view/index.vue'),children:[//sub-routes]}然后importconstrouterList=[];functionimportAll(route){route.keys().forEach((key)=>routerList.push(route(key).default));}importAll(require.context('./',true,/\.routes\.js/));constroutes=[{path:name:conmponent:},...routerList,]