To navigate to particular link from current url, you can do something like this,
constructor(private route: ActivatedRoute, private router: Router){}
ngOnInit() {
this.route.params.subscribe(params => {
// PARAMS CHANGED ..
let id = params['projectid'];
});
}
navigate(){
this.router.navigateByUrl(this.router.url.replace(id, newProjectId));
// replace parameter of navigateByUrl function to your required url
}
On ngOnInit function, we have subscribed to params so we can observe and executes our statements on any change in url parameter.
Edit
Case: where ids can be same
constructor(private route: ActivatedRoute, private router: Router){}
projectId:string;
userId: string;
ngOnInit() {
this.route.params.subscribe(params => {
this.projectId = params['projectid'];
this.userId = params['userId'];
});
}
navigate(){
// for /project/:projectId/users/:userId/profile
this.router.navigate(['/project', this.projectId, '/users',
this.userId, '/profile']);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…