Navigate relative with Angular 2 Router (Version 3)

前端 未结 4 1470
野性不改
野性不改 2021-02-01 12:31

How to navigate relative from /questions/123/step1 to /questions/123/step2 within a component using Router without string concatenation an

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 12:46

    First, inject router & ActivatedRoute on constructor

    constructor(private route:ActivatedRoute,private router:Router) { }
    

    then use to Click Event:

    onEditClick(){
            this.router.navigate(['edit'],{relativeTo:this.route});
    

    You navigate to the expected page.In my scenario, I wanted to go recipe /1 to edit the recipe. http://localhost:4200/recipes/1/edit

提交回复
热议问题