Closed
Description
I am building a large scale application with "mini applications" hosted within the application.
Each mini application is being developed by another team.
I would like to dynamically add nested child routes to an existing route to allow dynamic registration of each of the mini apps.
for example:
const routes = [
{path: 'a', component: ComponentA, name: 'a'},
{path: 'b', component: ComponentB, name: 'b'},
];
//MiniApp.js
export default Vue.extend({
beforeCreate () {
this.$router.addChildRoutes(this.$router.currentRoute.path, routes);
},
template: `
<div>
<div class="page-host">
<router-link to="{name: 'a'}">a</router-link>
<router-link to="{name: 'b'}">b</router-link>
<transition name="fade" mode="out-in">
<keep-alive><router-view class="view"></router-view></keep-alive>
</transition>
</div>
</div>`,
});
//The app itself
Vue.use(Router);
import MiniApp from "./MiniApp";
const config = {
linkActiveClass: 'active',
scrollBehavior: () => ({x: 0, y: 0}),
routes: [
{path: '/mini', component: MiniApp, name: 'mini'}},
]
};
let router = new Router(config);
const vue = new Vue({
router,
template: `
<div>
<div class="page-host">
<router-link to="/mini">a</router-link>
<transition name="fade" mode="out-in">
<keep-alive><router-view class="view"></router-view></keep-alive>
</transition>
</div>
</div>`,
}).$mount('#app');