How can I use an empty href attribute without redirect?

You can use:

<a href="javascript:;"">Link</a>

or maybe better if you don't want to use inline JavaScript:

<a href="" (click)="$event.preventDefault()">Link</a>

to realize a Link without any side-effect.


href="javascript:;" will produce an error after clicking link when Content-Security-Policy disallows inline scripts (script-src: 'self'; for example) (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src).

You can use empty href with event.preventDefault() on click instead.

<a href="" (click)="$event.preventDefault()">Link</a>