Skip to content

fix(bridge-vue3): pass hashRoute/memoryRoute to RemoteApp and fix path normalization#4551

Merged
2heal1 merged 8 commits intomodule-federation:mainfrom
LuisDev2001:fix/bridge-vue3-hash-route-support
Mar 18, 2026
Merged

fix(bridge-vue3): pass hashRoute/memoryRoute to RemoteApp and fix path normalization#4551
2heal1 merged 8 commits intomodule-federation:mainfrom
LuisDev2001:fix/bridge-vue3-hash-route-support

Conversation

@LuisDev2001
Copy link
Contributor

@LuisDev2001 LuisDev2001 commented Mar 15, 2026

Description

createRemoteAppComponent in vue3-bridge/src/create.ts accepted hashRoute and memoryRoute as part of its type definitions and they were fully implemented downstream (RemoteApp, provider.ts, processRoutes), but the h(RemoteApp, {...}) call never forwarded them — so they were always undefined at runtime.

Additionally, addBasenameToNestedRoutes in routeUtils.ts had two bugs:

  1. Path concatenation without separatorbasename + route.path produced /appprofile instead of /app/profile for relative child paths.
  2. Redirects not prefixed — routes with redirect: '/dashboard' were not prefixed with the basename, causing the remote app to redirect outside its scope (e.g. /#/dashboard instead of /#/barber/dashboard).

Changes

  • create.ts: Forward hashRoute and memoryRoute from createRemoteAppComponent options to the RemoteApp component via h().
  • routeUtils.ts: Fix path joining with / separator + normalize double slashes. Add redirect prefixing for both string and object redirects.
  • routeUtils.test.ts: Add 13 new unit tests covering hashRoute, memoryRoute, default web history, and redirect handling (24 total).

Usage example

Host app (Vue 3 + hash routing):

import { createRouter, createWebHashHistory } from 'vue-router'
import { createRemoteAppComponent } from '@module-federation/bridge-vue3'
import { loadRemote } from '@module-federation/runtime'

const BarberAppRemote = createRemoteAppComponent({
  loader: () => loadRemote('remoteBarberApp/export-app'),
  hashRoute: true,
})

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'welcome-host',
      component: () => import('@/views/WelcomeHost.vue'),
    },
    {
      path: '/barber/:pathMatch(.*)*',
      name: 'BarberApp',
      component: BarberAppRemote,
    },
  ],
})

Remote app (exported via bridge, no changes needed):

import { createBridgeComponent } from '@module-federation/bridge-vue3'
import App from './App.vue'
import router from './router'

export default createBridgeComponent({
  rootComponent: App,
  appOptions: ({ app }) => {
    return { router }
  },
})

Where the remote's router is:

import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    { path: '/', redirect: '/dashboard' },
    { path: '/dashboard', name: 'dashboard', component: () => import('../views/DashboardView.vue') },
    { path: '/about', name: 'about', component: () => import('../views/AboutView.vue') },
  ],
})

What happens at runtime:

  1. User navigates to http://localhost:3000/#/barber
  2. create.ts auto-detects basename = '/barber' from the matched route
  3. processRoutes receives hashRoute: true + basename: '/barber' → creates createWebHashHistory() and prefixes all route paths and redirects with /barber
  4. Remote's { path: '/', redirect: '/dashboard' } becomes { path: '/barber', redirect: '/barber/dashboard' }
  5. URL correctly stays as http://localhost:3000/#/barber/dashboard

Demo

2026-03-15.11-27-36.mp4

Related Issue

No existing issue — discovered that createRemoteAppComponent silently dropped hashRoute and memoryRoute params despite them being defined in ProviderParams and fully implemented in processRoutes.

Related Discussion

#4298

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation.

- Add hashRoute mode with basename prefix support in processRoutes

- Fix incorrect deprecation message in createRemoteComponent

- Update devDependencies: vite-plugin-dts, vue, vue-tsc

- Add comprehensive route processing tests
…shRoute mode

- Fix addBasenameToNestedRoutes to join paths with '/' separator instead of direct concatenation
- Add redirect prefixing support for string and object redirects in addBasenameToNestedRoutes
- Add unit tests for hashRoute, memoryRoute, default web history, and redirect handling
@changeset-bot
Copy link

changeset-bot bot commented Mar 15, 2026

🦋 Changeset detected

Latest commit: b51f930

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 45 packages
Name Type
@module-federation/bridge-vue3 Patch
@module-federation/runtime Patch
@module-federation/enhanced Patch
@module-federation/rspack Patch
@module-federation/webpack-bundler-runtime Patch
@module-federation/sdk Patch
@module-federation/runtime-tools Patch
@module-federation/managers Patch
@module-federation/manifest Patch
@module-federation/dts-plugin Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/devtools Patch
@module-federation/bridge-react Patch
@module-federation/bridge-shared Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/modern-js Patch
@module-federation/modern-js-v3 Patch
@module-federation/retry-plugin Patch
@module-federation/data-prefetch Patch
@module-federation/rsbuild-plugin Patch
@module-federation/error-codes Patch
@module-federation/inject-external-runtime-core-plugin Patch
@module-federation/runtime-core Patch
create-module-federation Patch
@module-federation/cli Patch
@module-federation/rspress-plugin Patch
@module-federation/treeshake-server Patch
@module-federation/treeshake-frontend Patch
@module-federation/metro Patch
@module-federation/metro-plugin-rnef Patch
@module-federation/metro-plugin-rnc-cli Patch
@module-federation/esbuild Patch
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/storybook-addon Patch
shared-tree-shaking-no-server-host Patch
shared-tree-shaking-no-server-provider Patch
@module-federation/utilities Patch
remote5 Patch
remote6 Patch
shared-tree-shaking-with-server-host Patch
shared-tree-shaking-with-server-provider Patch
website-new Patch
node-dynamic-remote-new-version Patch
node-dynamic-remote Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify
Copy link

netlify bot commented Mar 15, 2026

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit b51f930
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/69ba779028df9e0008b019db
😎 Deploy Preview https://deploy-preview-4551--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 361ab3551d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

… paths

- Extract prefixPath helper to centralize join + normalize logic
- Preserve intentional trailing slashes in paths and redirects (strict mode compat)
- Add tests for trailing slash preservation in hashRoute with basename
@2heal1
Copy link
Member

2heal1 commented Mar 17, 2026

need to resolve conflict

@LuisDev2001
Copy link
Contributor Author

Branch synced with latest main — merge conflict in pnpm-lock.yml has been resolved. Ready for review. @2heal1

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 18, 2026

Open in StackBlitz

@module-federation/devtools

pnpm add https://pkg.pr.new/@module-federation/devtools@b51f930

@module-federation/cli

pnpm add https://pkg.pr.new/@module-federation/cli@b51f930

create-module-federation

pnpm add https://pkg.pr.new/create-module-federation@b51f930

@module-federation/data-prefetch

pnpm add https://pkg.pr.new/@module-federation/data-prefetch@b51f930

@module-federation/dts-plugin

pnpm add https://pkg.pr.new/@module-federation/dts-plugin@b51f930

@module-federation/enhanced

pnpm add https://pkg.pr.new/@module-federation/enhanced@b51f930

@module-federation/error-codes

pnpm add https://pkg.pr.new/@module-federation/error-codes@b51f930

@module-federation/esbuild

pnpm add https://pkg.pr.new/@module-federation/esbuild@b51f930

@module-federation/managers

pnpm add https://pkg.pr.new/@module-federation/managers@b51f930

@module-federation/manifest

pnpm add https://pkg.pr.new/@module-federation/manifest@b51f930

@module-federation/metro

pnpm add https://pkg.pr.new/@module-federation/metro@b51f930

@module-federation/metro-plugin-rnc-cli

pnpm add https://pkg.pr.new/@module-federation/metro-plugin-rnc-cli@b51f930

@module-federation/metro-plugin-rnef

pnpm add https://pkg.pr.new/@module-federation/metro-plugin-rnef@b51f930

@module-federation/modern-js

pnpm add https://pkg.pr.new/@module-federation/modern-js@b51f930

@module-federation/modern-js-v3

pnpm add https://pkg.pr.new/@module-federation/modern-js-v3@b51f930

@module-federation/native-federation-tests

pnpm add https://pkg.pr.new/@module-federation/native-federation-tests@b51f930

@module-federation/native-federation-typescript

pnpm add https://pkg.pr.new/@module-federation/native-federation-typescript@b51f930

@module-federation/nextjs-mf

pnpm add https://pkg.pr.new/@module-federation/nextjs-mf@b51f930

@module-federation/node

pnpm add https://pkg.pr.new/@module-federation/node@b51f930

@module-federation/retry-plugin

pnpm add https://pkg.pr.new/@module-federation/retry-plugin@b51f930

@module-federation/rsbuild-plugin

pnpm add https://pkg.pr.new/@module-federation/rsbuild-plugin@b51f930

@module-federation/rspack

pnpm add https://pkg.pr.new/@module-federation/rspack@b51f930

@module-federation/rspress-plugin

pnpm add https://pkg.pr.new/@module-federation/rspress-plugin@b51f930

@module-federation/runtime

pnpm add https://pkg.pr.new/@module-federation/runtime@b51f930

@module-federation/runtime-core

pnpm add https://pkg.pr.new/@module-federation/runtime-core@b51f930

@module-federation/runtime-tools

pnpm add https://pkg.pr.new/@module-federation/runtime-tools@b51f930

@module-federation/sdk

pnpm add https://pkg.pr.new/@module-federation/sdk@b51f930

@module-federation/storybook-addon

pnpm add https://pkg.pr.new/@module-federation/storybook-addon@b51f930

@module-federation/third-party-dts-extractor

pnpm add https://pkg.pr.new/@module-federation/third-party-dts-extractor@b51f930

@module-federation/treeshake-frontend

pnpm add https://pkg.pr.new/@module-federation/treeshake-frontend@b51f930

@module-federation/treeshake-server

pnpm add https://pkg.pr.new/@module-federation/treeshake-server@b51f930

@module-federation/typescript

pnpm add https://pkg.pr.new/@module-federation/typescript@b51f930

@module-federation/utilities

pnpm add https://pkg.pr.new/@module-federation/utilities@b51f930

@module-federation/webpack-bundler-runtime

pnpm add https://pkg.pr.new/@module-federation/webpack-bundler-runtime@b51f930

@module-federation/bridge-react

pnpm add https://pkg.pr.new/@module-federation/bridge-react@b51f930

@module-federation/bridge-react-webpack-plugin

pnpm add https://pkg.pr.new/@module-federation/bridge-react-webpack-plugin@b51f930

@module-federation/bridge-shared

pnpm add https://pkg.pr.new/@module-federation/bridge-shared@b51f930

@module-federation/bridge-vue3

pnpm add https://pkg.pr.new/@module-federation/bridge-vue3@b51f930

@module-federation/inject-external-runtime-core-plugin

pnpm add https://pkg.pr.new/@module-federation/inject-external-runtime-core-plugin@b51f930

commit: b51f930

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

Bundle Size Report

16 package(s) changed, 24 unchanged.

Package dist + ESM entry

Package Total dist (raw) Delta ESM gzip Delta
@module-federation/bridge-vue3 144.9 kB +940 B (+0.6%) 22.2 kB +101 B (+0.4%)
@module-federation/cli 26.7 kB no change 786 B no change
@module-federation/core 39.1 kB no change 173 B no change
@module-federation/devtools 473.2 kB no change 3.9 kB no change
@module-federation/enhanced 810.5 kB no change 672 B no change
@module-federation/managers 69.9 kB no change 334 B no change
@module-federation/manifest 138.4 kB no change 182 B no change
@module-federation/metro-plugin-rnc-cli 0 B no change 314 B no change
@module-federation/modern-js 186.8 kB +1.1 kB (+0.6%) 1.2 kB +4 B (+0.3%)
@module-federation/modern-js-v3 178.0 kB +1.1 kB (+0.6%) 875 B +3 B (+0.3%)
@module-federation/node 189.2 kB no change 217 B no change
@module-federation/runtime-core 251.8 kB +8 B (+0.0%) 477 B no change
@module-federation/storybook-addon 77.0 kB no change 100 B no change
@module-federation/treeshake-frontend 635.6 kB +1.4 kB (+0.2%) 0 B no change
@module-federation/treeshake-server 818.2 kB +1.4 kB (+0.2%) 8.0 kB no change
@module-federation/utilities 110.6 kB no change 328 B no change

Bundle targets

Package Web bundle (gzip) Delta Node bundle (gzip) Delta
@module-federation/bridge-vue3 17.0 kB +91 B (+0.5%) 16.7 kB +87 B (+0.5%)
@module-federation/cli 2.3 kB -34 B (-1.4%) 2.3 kB -34 B (-1.4%)
@module-federation/core 1.1 kB -33 B (-2.9%) 1.0 kB -32 B (-3.0%)
@module-federation/devtools 20.8 kB -28 B (-0.1%) 20.8 kB -28 B (-0.1%)
@module-federation/enhanced 2.6 kB -45 B (-1.6%) 2.6 kB -45 B (-1.6%)
@module-federation/managers 2.4 kB -27 B (-1.1%) 2.4 kB -27 B (-1.1%)
@module-federation/manifest 6.2 kB -39 B (-0.6%) 6.2 kB -39 B (-0.6%)
@module-federation/metro-plugin-rnc-cli 411 B -27 B (-6.2%) 411 B -27 B (-6.2%)
@module-federation/modern-js 4.7 kB no change 4.7 kB no change
@module-federation/modern-js-v3 4.5 kB no change 4.5 kB no change
@module-federation/node 9.2 kB -29 B (-0.3%) 9.2 kB -29 B (-0.3%)
@module-federation/runtime-core 13.7 kB no change 13.4 kB no change
@module-federation/storybook-addon 1.9 kB -25 B (-1.3%) 1.7 kB -25 B (-1.4%)
@module-federation/treeshake-frontend n/a n/a n/a n/a
@module-federation/treeshake-server 5.7 kB no change 5.7 kB no change
@module-federation/utilities 2.6 kB -33 B (-1.2%) 2.6 kB -33 B (-1.2%)

Consumer scenarios

Scenario Web output (gzip) Delta Node output (gzip) Delta Gap (node-web) Delta
Enhanced remoteEntry 19.5 kB -13 B (-0.1%) 20.5 kB -18 B (-0.1%) +1.0 kB -5 B

Total dist (raw): 6.31 MB (+5.9 kB (+0.1%))
Total ESM gzip: 73.5 kB (+108 B (+0.1%))
Total web bundle (gzip): 177.9 kB (-229 B (-0.1%))
Total node bundle (gzip): 178.4 kB (-232 B (-0.1%))
Tracked ./bundler entry gzip: 556 B (no change)
Tracked ./bundler web bundle (gzip): 4.5 kB (no change)
Tracked ./bundler node bundle (gzip): 4.5 kB (no change)

Bundle sizes are generated with rslib (Rspack). Package-root metrics preserve the historical report. Tracked subpath exports such as ./bundler are measured separately so ENV_TARGET-driven tree-shaking is visible. Bare imports are externalized to keep package-level sizes consistent, and assets are emitted as resources.

@2heal1 2heal1 merged commit 7489d7c into module-federation:main Mar 18, 2026
23 checks passed
@2heal1 2heal1 mentioned this pull request Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants