首先在路由字典中,接收值的組件中加上:/:id瀏覽器
在發送值的組件中,發送值的方式有幾種。this
第一種:<a routerLink="/detail/1">新聞詳情1</a>url
利用routerLink,在跳轉的組件後加上要傳過去的值spa
接着在接收值的組件中,也就是detail組件裏,引入ActivatedRoute,並實例化.net
而後須要使用route,就能獲取傳過的值3d
*navigate的用法code
1.以根路由跳轉/loginrouter
this.router.navigate(['login']);
2.設置relativeTo相對當前路由跳轉,route是ActivatedRoute的實例,使用須要導入ActivatedRoutehtm
3.路由中傳參數 /login?name=1blog
4.preserveQueryParams默認值爲false,設爲true,保留以前路由中的查詢參數/login?name=1 to /home?name=1
5.路由中錨點跳轉 /home#top
this.router.navigate(['home'],{ fragment: 'top' });
6.preserveFragment默認爲false,設爲true,保留以前路由中的錨點/home#top to /role#top
this.router.navigate(['/role'], { preserveFragment: true });
7.skipLocationChange默認爲false,設爲true,路由跳轉時瀏覽器中的url會保持不變,可是傳入的參數依然有效
8.replaceUrl默認爲true,設爲false,路由不會進行跳轉