-
Notifications
You must be signed in to change notification settings - Fork 4
URL Specification
@microfrontend/controller uses a custom URL hash format to encode the state of all microfrontends across outlets.
| Symbol | Meaning |
|---|---|
; |
Separates outlets |
~ |
Separates outlet name from its routes |
! |
Separates routes of different microfrontends within an outlet |
When using a single (default) outlet, the outlet name is omitted. The hash consists of microfrontend routes separated by !:
#metaRoute1/subRoute!metaRoute2/subRoute
Rules:
- The first route in the list is the active (visible) microfrontend
- Subsequent routes are hidden but their state is preserved
- Each route consists of a
metaRouteoptionally followed by/subRoute
| URL Hash | Active MF | Active Subroute | Hidden MFs |
|---|---|---|---|
#a |
a |
(none) | (none) |
#a/settings |
a |
settings |
(none) |
#a!b |
a |
(none) | b |
#a/settings!b |
a |
settings |
b (no subroute) |
#a/settings!b/home |
a |
settings |
b (subroute home) |
#b!a/settings |
b |
(none) |
a (subroute settings) |
Given the URL hash:
#a/b/c!x/y/z
This encodes two microfrontends in the default outlet:
-
Microfrontend
a:- Currently visible (first in the list)
- Internal subroute:
b/c
-
Microfrontend
x:- Currently hidden (not first)
- Internal subroute:
y/z
Note: The current version supports a single outlet only. Named outlet syntax is reserved for future use.
The full format includes outlet names, with outlets separated by ;:
#outlet1~metaRoute1/sub!metaRoute2/sub;outlet2~metaRoute3/sub
#outlet1~a/b/c!x/y/z;outlet2~k/l/m
This encodes two outlets:
outlet1 contains two microfrontends:
-
Microfrontend
a— visible, subrouteb/c -
Microfrontend
x— hidden, subroutey/z
outlet2 contains one microfrontend:
-
Microfrontend
k— visible, subroutel/m
The UrlHelper class (internal) handles URL construction and parsing:
-
Parsing: Splits by
;(outlets), then~(outlet name vs routes), then!(individual routes), then/(metaRoute vs subRoute) - Construction: Reverses the process to build a full hash from internal state
When the URL hash changes:
-
User click navigation (e.g.,
router.go('b')) → useshistory.pushState()to create a new browser history entry -
Programmatic/internal updates (e.g., microfrontend reports a route change) → uses
history.replaceState()to update the current entry without creating a new one -
Back/forward button → triggers a
hashchangeevent, which theMetaRouterhandles by activating the encoded route
This design ensures that the browser's back and forward buttons correctly navigate between microfrontend states.
The FrameConfig.hashPrefix (default: '/') is prepended to hash routes when constructing iframe URLs. This allows microfrontends to use hash-based routing (e.g., #/settings inside the iframe) while the shell manages the meta-routing hash.
@microfrontend — MIT License — npm — GitHub
Getting Started
Guides
API Reference
Contributing