1. 程式人生 > >navigate是Router類的一個方法,主要用來跳轉路由。

navigate是Router類的一個方法,主要用來跳轉路由。

res spa 不變 dex avi cell 方法 plain 當前

navigate是Router類的一個方法,主要用來跳轉路由。

1 2 3 4 5 6 7 8 9 interface NavigationExtras { relativeTo : ActivatedRoute queryParams : Params fragment : string preserveQueryParams : boolean preserveFragment : boolean skipLocationChange : boolean replaceUrl : boolean }

1.this.router.navigate([‘user‘, 1]);

以根路由為起點跳轉

2.this.router.navigate([‘user‘, 1],{relativeTo: route});

默認值為根路由,設置後相對當前路由跳轉,route是ActivatedRoute的實例,使用需要導入ActivatedRoute

3.this.router.navigate([‘user‘, 1],{ queryParams: { id: 1 } });
路由中傳參數 /user/1?id=1

4.this.router.navigate([‘view‘, 1], { preserveQueryParams: true });

默認值為false,設為true,保留之前路由中的查詢參數/user?id=1 to /view?id=1

5.this.router.navigate([‘user‘, 1],{ fragment: ‘top‘ });

路由中錨點跳轉 /user/1#top

6.this.router.navigate([‘/view‘], { preserveFragment: true });

默認值為false,設為true,保留之前路由中的錨點/user/1#top to /view#top

7.this.router.navigate([‘/user‘,1], { skipLocationChange: true });

默認值為false,設為true路由跳轉時瀏覽器中的url會保持不變,但是傳入的參數依然有效

8.this.router.navigate([‘/user‘,1], { replaceUrl: true });

navigate是Router類的一個方法,主要用來跳轉路由。