0
votes

I'd like to return to my HTML page custom router links.

In my HTML I have:

<span [innerHTML]="value | toRouterLink"></span>

the toRouterLink pipe returns a sanitized router link:

return this.sanitizer.bypassSecurityTrustHtml(`<a routerLink="/item/something">${value}</a>`);

When I click on it, nothing happens, as if there's no directive at all.

If however I swap "routerLink" with "href", clicking the link works (although naturally it leads to nowhere).

How do I make the routerLink work after sanitization?

It seems that any directive doesn't work, e.g. (click)="myFunc()" doesn't call myFunc().

From what I understood from other topics on the subject the sanitization process should register directives and anything else related to the angular environment, but for some reason it doesn't happen.

1

1 Answers

0
votes

You could instead try

return this.sanitizer.bypassSecurityTrustURL("/item/something");
<span>
  <a [routerLink]="value | toRouterLink">${value}</a>
</span>