0

When I pass a [queryParams] inside a routerlink the link simply doesn't work:

<app-notifications *ngIf="pendingBillets" [routerLink]="'/app/billing/billets-management/billet'" // this simply won't work
                    [queryParams]="{filter: 'pendingBank'}"
                    [isError]="true">
                        Você possui {{pendingBillets}} boleto(s) não cancelado(s) no banco.
</app-notifications>
<app-notifications  [routerLink]="'/app/operational/wash-engine-turn'" // this one is working
                    [queryParams]="{filter: 'never'}">
                        Existem embarcações ativas que nunca tiveram lavação ou giro de motor.
    </app-notifications>

If I remove [queryParams]="{filter: 'pendingBank'}" from the app-notifications, it works just fine.

app-notifications.component.ts:

@Component({
  selector: 'app-notifications',
  templateUrl: './notifications.component.html',
  styleUrls: ['./notifications.component.scss']
})
export class NotificationsComponent implements OnInit {

  @Input() isError = false;
  @Input() routerLink;

  styleClass;

  constructor() { }

  ngOnInit(): void {
    this.styleClass = this.isError ? ['error'] : ['warn'];
    if (this.routerLink === undefined) {
      this.styleClass.push('not-clickable');
    }
  }

billets-management/billet component:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-billet',
  templateUrl: './billet.component.html',
  styleUrls: ['./billet.component.scss']
})
export class BilletComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }

}
rafaelpadu
  • 1,134
  • 2
  • 6
  • 20
  • It's something REALLY related to the queryParams, because if I add `queryParamsHandling="preserve"`, the link works just fine but without the queryParams obviously... – rafaelpadu May 17 '22 at 12:44

1 Answers1

0

I'm not sure this solves your problem, but the routerlink should end on /

Something like:

<app-notifications *ngIf="pendingBillets" [routerLink]="'/app/billing/billets-management/billet/'" // this simply won't work
                    [queryParams]="{filter: 'pendingBank'}"
                    [isError]="true">
                        Você possui {{pendingBillets}} boleto(s) não cancelado(s) no banco.
</app-notifications>
<app-notifications  [routerLink]="'/app/operational/wash-engine-turn/'" // this one is working
                    [queryParams]="{filter: 'never'}">
                        Existem embarcações ativas que nunca tiveram lavação ou giro de motor.
</app-notifications>

See this answer for more detail on queryparams with routerlink.

Manuel Tomás
  • 540
  • 3
  • 11