Skip to content

Commit 113a989

Browse files
arbrandesclaude
andcommitted
docs: explain route roles and external routes
Adds a brief explainer covering the route role field, the externalRoutes site config entry, and how getUrlByRouteRole resolves a role against apps first and falls back to externalRoutes. First entry in a planned set of documentation additions. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3cc4b35 commit 113a989

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Route roles and external routes
2+
3+
## Route roles
4+
5+
A route role is a string identifier attached to a route via its `handle.roles` array. It names the purpose the route fulfills (e.g. "the profile page", "the account settings page") independent of its URL path.
6+
7+
Use reverse-domain notation: `org.openedx.frontend.role.profile`.
8+
9+
```tsx
10+
const app: App = {
11+
appId: 'org.openedx.frontend.app.example',
12+
routes: [{
13+
path: '/example',
14+
Component: ExamplePage,
15+
handle: {
16+
roles: ['org.openedx.frontend.role.example'],
17+
},
18+
}],
19+
};
20+
```
21+
22+
Resolve a role to a URL with `getUrlByRouteRole(role)`. It walks every registered app's routes, recurses into `children`, and returns the full path of the first route whose `handle.roles` includes the requested role. Returns `null` if no match.
23+
24+
A single route may declare multiple roles. A single role may appear on multiple routes; the first match wins.
25+
26+
## External routes
27+
28+
An `externalRoute` maps a role to an absolute URL that is not served by any registered app, typically a separate MFE or backend page.
29+
30+
```tsx
31+
const siteConfig: SiteConfig = {
32+
externalRoutes: [
33+
{
34+
role: 'org.openedx.frontend.role.profile',
35+
url: 'http://apps.local.openedx.io:1995/profile/',
36+
},
37+
],
38+
// ...
39+
};
40+
```
41+
42+
Declared at the top level of `SiteConfig`, not inside an app. Each entry is `{ role, url }`.
43+
44+
## How they interact
45+
46+
`getUrlByRouteRole(role)` checks `apps[].routes` first, then falls back to `siteConfig.externalRoutes`. This means a role can resolve to either an in-site route path (when an app provides it) or an absolute external URL (when an MFE outside the current site provides it), and call sites do not need to know which.
47+
48+
This lets a deployment swap a feature between in-site and external by changing config alone: drop the app from `apps`, add an `externalRoutes` entry for the same role, and every `getUrlByRouteRole` caller updates automatically.
49+
50+
If the same role is declared by both an app route and an `externalRoutes` entry, the app route wins.

0 commit comments

Comments
 (0)