Skip to content

Bridge vue3使用被封装应用的路由,保留原有路由拦截;暴露basename配置; #3585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/bridge/vue3-bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"preview": "vite preview"
},
"peerDependencies": {
"vue": "=3",
"vue-router": "=3"
"vue": "^3.0.0",
"vue-router": "^4.0.0"
},
"dependencies": {
"@module-federation/bridge-shared": "workspace:*",
Expand Down
19 changes: 10 additions & 9 deletions packages/bridge/vue3-bridge/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function createRemoteComponent(info: {
export?: string;
asyncComponentOptions?: Omit<AsyncComponentOptions, 'loader'>;
rootAttrs?: Record<string, unknown>;
basename?: string;
}) {
return defineAsyncComponent({
__APP_VERSION__,
Expand All @@ -18,15 +19,15 @@ export function createRemoteComponent(info: {
loader: async () => {
const route = useRoute();

let basename = '/';
const matchPath = route.matched[0]?.path;
if (matchPath) {
if (matchPath.endsWith('/:pathMatch(.*)*')) {
basename = matchPath.replace('/:pathMatch(.*)*', '');
} else {
basename = route.matched[0].path;
}
}
const basename = info?.basename || '/';
// const matchPath = route.matched[0]?.path;
// if (matchPath) {
// if (matchPath.endsWith('/:pathMatch(.*)*')) {
// basename = matchPath.replace('/:pathMatch(.*)*', '');
// } else {
// basename = route.matched[0].path;
// }
// }

const exportName = info?.export || 'default';
LoggerInstance.debug(`createRemoteComponent LazyComponent create >>>`, {
Expand Down
34 changes: 17 additions & 17 deletions packages/bridge/vue3-bridge/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,26 @@ export function createBridgeComponent(bridgeInfo: ProviderFnParams) {
});

if (bridgeOptions?.router) {
const history = info.memoryRoute
? VueRouter.createMemoryHistory(info.basename)
: VueRouter.createWebHistory(info.basename);
// const history = info.memoryRoute
// ? VueRouter.createMemoryHistory(info.basename)
// : VueRouter.createWebHistory(info.basename);

const router = VueRouter.createRouter({
...bridgeOptions.router.options,
history,
routes: bridgeOptions.router.getRoutes(),
});
// const router = VueRouter.createRouter({
// ...bridgeOptions.router.options,
// history,
// routes: bridgeOptions.router.getRoutes(),
// });

LoggerInstance.debug(`createBridgeComponent render router info>>>`, {
moduleName,
router,
});
// memory route Initializes the route
if (memoryRoute) {
await router.push(memoryRoute.entryPath);
}
// LoggerInstance.debug(`createBridgeComponent render router info>>>`, {
// moduleName,
// router,
// });
// // memory route Initializes the route
// if (memoryRoute) {
// await router.push(memoryRoute.entryPath);
// }

app.use(router);
app.use(bridgeOptions.router);
}

app.mount(dom);
Expand Down
3 changes: 2 additions & 1 deletion packages/chrome-devtools/install-deps.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ if [ "$GITHUB_ACTIONS" = "true" ]; then
npx playwright install-deps && npx playwright install
else
echo "Not running in GitHub Actions environment."
# 在这里放置不在 GitHub Actions 环境时要执行的命令
# Commands to execute when not running in GitHub Actions environment
npx playwright install-deps && npx playwright install
fi
Loading