首先在路由字典中,接收值的组件中加上:/: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,路由不会进行跳转