本文介绍了Vue-router 类似Vuex实现组件化开发的示例,分享给大家,具体如下:
随着项目越来越大,把所有route写在一个文件里就显得杂乱。
#单个组件路由 import a from '../components/a' export default { path: '/a', name: 'a', component: a } import arouter from 'xxx' export default new Router({ routes: [ arouter ] }) #多个组件路由 import a from '../components/a' import b from '../components/b' export default [{ path: '/a', name: 'a', component: a }, { path: '/b', name: 'b', component: b }] #arouter.js export default new Router({ routes: [ ...arouter//扩展运算符 ] })