fix(portal-shell): catch-all route prevents NG04002 on /fr in dev mode
CI / scan (pull_request) Successful in 3m0s
CI / check (pull_request) Successful in 3m20s
CI / commits (pull_request) Successful in 3m18s
CI / a11y (pull_request) Successful in 2m2s
CI / perf (pull_request) Successful in 5m45s

Reproducer: `nx serve portal-shell` (source-locale dev server, no
`--localize`), open the home page, click the locale switcher's
"Français" entry. The switcher rewrites the URL to `/fr/` and
hard-refreshes; the Angular CLI dev server applies its SPA fallback
and serves the same source `index.html` for every path. The source
bundle boots with `<base href="/">`, the router tries to match
`/fr/` and finds no route → `NG04002: Cannot match any routes.
URL Segment: 'fr'` in the bootstrap promise rejection.

Fix: add a `{ path: '**', redirectTo: '' }` catch-all so unknown
paths bounce to home gracefully. In production this is a no-op
because each locale ships with its own `<base href="/{locale}/">`
and the locale segment is stripped before route matching — `/fr/foo`
hits the bundle's `foo` route, not the wildcard. The route also
serves as a defensive 404-to-home for any future bad URL in prod.

The locale switcher's actual limitation in dev (no per-locale
bundle, switching can only land on the source locale) stands; this
just turns the ugly error into a silent bounce so the dev iteration
is not interrupted.
This commit is contained in:
Julien Gautier
2026-05-11 22:07:50 +02:00
parent 192cc483b6
commit 0e0419ec5e
+12
View File
@@ -31,4 +31,16 @@ export const appRoutes: Route[] = [
redirectTo: 'accessibility',
pathMatch: 'full',
},
// Catch-all. In production each locale ships with its own
// `<base href="/{locale}/">`, so the router never actually sees
// the locale segment — `/fr/foo` is normalised to `foo` before
// route matching, and unknown paths land here for a graceful
// bounce to home. In dev (`nx serve`) the dev server serves the
// source bundle for any URL, including `/fr/...`; without this
// fallback the router throws NG04002 trying to match `fr` as a
// segment.
{
path: '**',
redirectTo: '',
},
];