[英]How to refresh the page in navigating from one page to other page in angular
在我的 angular 应用程序中,我有一些带路由器的导航页面。
我的要求是在导航时必须重新加载页面。
.component.ts
if(ID == 0){
this.router.navigate(['./Profilepage/' + ID]);
}
else{
this.router.navigate(['./dashboard']);
}
从上面的代码中,如果我已经在具有某些 ID 的 Profilepage 中,并且如果满足 if 条件,则它必须为具有该 ID 的特定 Profilepage go。
但对我来说,它并没有显示重定向,并且只有在刷新页面后才会发生。
谁能帮我 go 到具有 ID 的特定页面(如果条件满足)。
你的问题不是很清楚,但我想我明白了:
你需要“听”路线,这样你就可以检测路线的每一个变化并根据该变化进行导航。 尝试这样的事情:
import { ActivatedRoute, Params } from '@angular/router';
export class SomeClass implements OnInit {
paramFromRoute;
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.paramFromRoute = this.route.snapshot.params['paramName']; // this one is
// required for getting it first time
this.route.params.subscribe((params:Params)=>{
this.paramFromRoute = params['paramName'] // whenever route is changed, this
function will triggered.
});
// for queryParams you can subscribe to this.route.queryParams
}
}
我的猜测是您想根据路由器参数中的 id 使用新配置文件更新视图。 这意味着您必须监听已激活路由的变化,并且根本不需要重新加载页面。
有关示例,请参见此页面: https://angular-training-guide.rangle.io/routing/routeparams
constructor(private activatedRoute: ActivatedRoute) {}
ngOnInit() {
this.activatedRoute.params
.pipe(
map(params => params.id)
)
.subscribe(profileId => {
this.profileId = +profileId; // (+) converts string 'id' to a number
// Update view or profile object to load the details here.
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.