问题描述: 当使用Angular的路由功能进行页面跳转时,URL地址会发生变化,但是页面内容并没有刷新。
解决方法:
import { Router } from '@angular/router';
constructor(private router: Router) {}
// 跳转到指定路由
goToRoute(route: string) {
this.router.navigate([route]);
}
import { Router } from '@angular/router';
constructor(private router: Router) {}
// 跳转到指定URL
goToURL(url: string) {
this.router.navigateByUrl(url, { skipLocationChange: true }).then(() => {
this.router.navigate([url]);
});
}
import { ActivatedRoute } from '@angular/router';
constructor(private route: ActivatedRoute) {}
ngOnInit() {
this.route.params.subscribe(params => {
// 执行页面刷新操作
});
}
以上是几种解决“Angular路由刷新URL,但页面未能刷新。”问题的常用方法,根据具体情况选择适合的解决方案。