vue如何实现动态路由addRoute

vue中添加动态路由

src/router/index.js

```
import Vue from 'vue';
import Router from 'vue-router';
import HelloWorld from '@/components/page/BaseTable.vue'
import VueRouter from 'vue-router';
Vue.use(Router);

const constantRoutes = [
{
path: '/table',
component: HelloWorld,
meta: { title: '基础表格' }
}
]
const createRouter = () => new VueRouter({
mode:'hash',
base:process.env.BASE_URL,
routes: constantRoutes
})
const router = createRouter()
const routeObj =
{
path: '/form',
component: () => import(/* webpackChunkName: "table" */ '../components/page/BaseForm.vue'),
meta: { title: '基础表单' }
}
router.addRoute(routeObj)
const routeObj1 =
{
path: '/test',
component: () => import(/* webpackChunkName: "table" */ '../components/page/BaseForm.vue'),
meta: { title: '基础表单' }
}
router.addRoute(routeObj1)
export default router
```

    A+
发布日期:2022年11月15日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: