Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable routing to <a href="#" > in angular 8?

I'm using local reference like this

<a class="btn-floating btn-large blue" href="#">button</a>

But Angular redirects me to some another link localhost:4200/#

like image 269
Nishant soni Avatar asked Nov 29 '25 00:11

Nishant soni


1 Answers

just call preventDefault method of the click event

<a class="btn-floating btn-large blue" href="#" (click)="$event.preventDefault()">
button
</a>

or just remove the href attribute

<a class="btn-floating btn-large blue" >
button
</a>

you navigate in the page by using scrollIntoView method.

<a (click)="skils.scrollIntoView({behavior: 'smooth'})">Skils 🔽</a>
....
<div #skils>...</div>

demo 🚀

like image 131
Muhammed Albarmavi Avatar answered Nov 30 '25 23:11

Muhammed Albarmavi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!