SoFunction
Updated on 2025-04-08

Solve the problem of Angular2 refreshing page

This problem is usually caused by the fact that we forget to add the type attribute when using <button> in the <form> form. In the form, if we forget to add attributes to the button, it will default to submit. If it bubbles upwards in the child element, it will trigger submit.

<button (click)="toDetail()">detail</button>
toDetail() {
 this._router.navigate(['/detail']);
}

Solution:

1. Add type

<button type="button" (click)="toDetail()">detail</button>

Add false

<button (click)="toDetail();false">detail</button>

3. Function returns false

toDetail:boolean(){
 return false;
}

The above article solves the problem of refreshing the Angular2 page is all the content I share with you. I hope you can give you a reference and I hope you can support me more.