Search code examples
angulartypescriptroutesangular7

Angular 7 router.navigate() queryParams - parsing multiple values for the same param


So, basicaly I have a route to which I have to pass a few values, but they are all regarding the same parameter. This is the URL I wish to navigate to:

http://localhost:4200/home/path?status=1&status=5

I tried to set the routing through router.navigate(), but this is not allowed since it's regarding the same parameter (An object literal cannot have multiple properties with the same name):

this.router.navigate(["/home/path"], {
      queryParams: { status: '1', status: '5'},
    });

Thanks in advance for any advices and suggestions


Solution

  • So the solution was pretty much under my nose, as I replied to @derstauner:

    I can pass the queryParams as an array. So simply by stating that status=[1,5], the redirecting works fine:

    this.router.navigate(["/home/path"], {
          queryParams: { status: [1,5]},
        });