1

I am using Angular 9 (Ivy). I want to trigger router Guards without actually changing the page. With the current abilities of Angular, how can I accomplish this?

This following is example code that does not work but should give an idea of what I am trying to do.

In the template:

<button type="button" (click)="triggerGuards()">Trigger</button>

In the component:

public triggerGuards(): void {
    // this `navigate()` call does *not* trigger Guards //
    this._router.navigate([this._router.url]).then(() => {
        this._doSomethingElse();
    });
}

I also tried this._router.navigateByUrl(this._router.url + '?') but this does not fire the Guards either.

How can I trigger router Guards without changing pages?

ebakunin
  • 3,621
  • 7
  • 30
  • 49
  • runGuardsAndResolvers: 'always' Try setting this in routing module where u configured your guards. Also u may need to set onSameUrlNavigation: 'reload' – SanTos A Aug 03 '20 at 02:04

0 Answers0