App1(host) include App2(remote), router is not working #195
-
App1:host, vue3, simple application, just show h1 APP1 App1 include App2, use module-federation. when i execute App1, get a warn, and router is not working :(
So if App2 is remote module, can it use router?
<script>
import { defineAsyncComponent } from "vue";
export default {
name: "App",
components: {
RemoteApp: defineAsyncComponent(() => import("app2/App")),
},
};
</script>
<template>
<h1>APP1</h1>
<RemoteApp></RemoteApp>
</template>
export default defineConfig({
plugins: [
vue(),
federation({
name: "app1",
filename: "remoteEntry.js",
remotes: {
app2: "http://localhost:4173/assets/remoteEntry.js",
},
shared: ["vue", "vue-router", "vuex"],
}),
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
});
export default defineConfig({
plugins: [
vue(),
federation({
name: "app2",
filename: "remoteEntry.js",
exposes: {
"./App": "./src/App.vue",
},
shared: ["vue", "vue-router", "vuex"],
}),
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
build: {
target: "esnext",
minify: false,
cssCodeSplit: true,
rollupOptions: {
output: {
minifyInternalExports: false,
},
},
},
}); github-link: https://github.com/franklion/vue-module-federation |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Thanks for your feedback, I guess the reason for this problem is the same as the previous issue (#139 (comment)), the router should also be bound to the vue instance, remote and host are running in different vue instances, so they can't share the router, when you need to define the router, you have to define it on the host side, like this const router = createRouter({
history: createWebHashHistory(),
routes: [
{
path: '/',
redirect: '/introduce'
},
{
path: '/login',
name: 'login',
component: defineAsyncComponent(() => import("router-remote/Login"))
},
{
path: '/shopping',
name: 'shopping',
component: () => import( '../views/Shopping.vue')
}
,
{
path: '/account',
name: 'account',
component: () => import('../views/Account.vue')
}
]
}) |
Beta Was this translation helpful? Give feedback.
Thanks for your feedback, I guess the reason for this problem is the same as the previous issue (#139 (comment)), the router should also be bound to the vue instance, remote and host are running in different vue instances, so they can't share the router, when you need to define the router, you have to define it on the host side, like this