这可能是由于浏览器缓存的原因导致的。可以通过添加随机数字在URL中来强制刷新。例如:
HTML模板:
My Page
组件:
import { Component } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-example',
templateUrl: './example.component.html',
styleUrls: ['./example.component.css']
})
export class ExampleComponent {
constructor(private router: Router) { }
forceReload() {
const currentUrl = this.router.url; //获取当前路由
this.router.navigateByUrl('/', { skipLocationChange: true }).then(() => { //刷新路由
this.router.navigate([currentUrl]); //重新导航
});
}
}