I'm building a Micro Frontend app based on Vue using Module Federation with Vite with the following structure:
Vue Host app:
- has a vue-router that will load the required micro frontends.
- the router has a base url named "/app".
- The path "/login" is loading properly the micro frontend (a Vue view) exported with Module Federation.
Vue Child app:
- This is loaded inside the host when accesing the "/login" route.
- has another vue-router for the internal navigation
- the base url is different to the host app.
The problem is that, when I try to navigate to different views inside the child app using router-link or "router.push", the Host app is updating the URL, and not the Child app.
This is how I expose the view from the child app:
federation({
name: 'login-mf',
filename: 'loginEntry.js',
exposes: {
'./LoginMF': './src/views/Login.vue',
},
shared: ["vue"]
})
This is the View I expose:
<template>
<p>Login view</p>
<router-link to="LoginForm">Login</router-link>
<router-link to="TestView">TestView</router-link>
<router-view></router-view>
</template>
And the routes:
const routes = [
{ path: '/', redirect: "/form" },
{ path: "/form", component: Login },
{ path: '/test/:id', name: "TestView", component: Test },
]
const router = createRouter({
history: createWebHistory("/login"),
routes,
})
In the host app I get the code exposed like this:
federation({
name: "host",
filename: "loginEntry.js",
remotes: {
"login-mf": {
external: "http://localhost:5005/assets/loginEntry.js",
format: 'esm',
from: 'vite'
},
},
shared: ["vue", "vue-router"]
})
And set the router like this:
const LoginMF = () => import("login-mf/LoginMF")
const routes = [
{path: "/", component: HelloWorld },
{ path: '/login', component: LoginMF },
]
const router = createRouter({
history: createWebHistory('/app/'),
})
How can I get the internal navigation of the internal app to work properly? Is there a way to "scope" the routers?