You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Router serializes null/undefined matrix parameters as the strings "null" and "undefined" #72208
Which @angular/* package(s) are the source of the bug?
router
Is this a regression?
No
Description
Matrix parameters with null or undefined values end up in the URL as the literal strings "null" and "undefined", while the same values passed as query parameters are removed:
The same applies to routerLink and createUrlTree, e.g. [routerLink]="['/products', {category: selectedCategory()}]".
The routing guide presents matrix parameters as optional route parameters, so passing an object whose optional fields are unset is a natural pattern. The component then receives a non-empty string, so checks like params.get('category') ?? 'all' no longer apply, and the URL shows ;category=undefined.
The cause is stringify() in packages/router/src/create_url_tree.ts, which converts every value with a template string. Query parameters skip null/undefined explicitly (see should remove query params with null or undefined values, and 2dd93cd which aligned createUrlTreeFromSnapshot with Router.createUrlTree).
I could not find documentation stating either behavior for matrix parameters, so this may be intentional. If it is not, I opened a PR that drops null/undefined matrix parameters the same way query parameters are dropped: #72207. Since the current behavior is old, it might count as a breaking change; I'm happy to adjust the PR accordingly.
Please provide a link to a minimal reproduction of the bug
Inline snippet above. Reproduced against a build of main at 568c48b.
Please provide the exception or error you saw
No exception. Resulting URL: /products;category=undefined;page=null
Please provide the environment you discovered this bug in (run ng version)
@angular/router built from main (568c48b796), Node.js 26.3.0
Activity