Visitar URL original
Inconsistent behavior in processing query params Params across different router functions · Issue #71540 · angular/angular · GitHub
The Wayback Machine - https://web.archive.org/web/20261024035510/https://github.com/angular/angular/issues/71540
Skip to content

Inconsistent behavior in processing query params Params across different router functions #71540

Open

Description

@Erbenos

Which @angular/* package(s) are the source of the bug?

router

Is this a regression?

No (same on 21)

Description

All related functions, to my knowledge, except createUrlTreeFromSnapshot, allow removing specific parameters from URLs by specifing their keys with null-ish value, eg.:

this.router.navigate(['./'], { queryParams: { hello: null } });

Above would remove "hello" query parameter when executed.

The createUrlTreeFromSnapshot however behaves differently:

 this.router.navigateByUrl(
    createUrlTreeFromSnapshot(this.activatedRoute.snapshot, [], {
      hello: null,
    })
  );

Above would set "hello" query parameter to "null" (so ?hello=null).

This is especially perplexing, given constructing URL tree manually works just fine:

this.router.navigateByUrl(
    this.router.createUrlTree(['/'], { queryParams: { hello: null } })
);

above would also clear the "hello" key.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/stackblitz-starters-yphtdp7t?file=src%2Fmain.ts

Please provide the exception or error you saw


Please provide the environment you discovered this bug in (run ng version)

Angular 22

Anything else?

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions