在路由中传递参数分为以下三种:
第一种:在查询参数中传递数据
<a [routerLink]="['/home']" [queryParams]="{id:1}">查询</a>
/home?id=1 => ActivatedRoute.snapshot.queryParams[id]
第二种:在路由路径中传递数据(组件间传递数据)
<a [routerLink]="['/home', 1]">查询</a>
{ path:/home/:id } => /home/1 => ActivatedRoute.snapshot.params[id]
{ path:/home/:id } => /home/1 =>this.activatedRoute.params.subscribe(obj=>this.id = obj.id)
第三种:在路由配置中传递数据
{ path:/XXX,component:XXXComponent,data:[{isFor:true}] } => ActivatedRoute.data[0].[isFor]
重定向路由:
{ path:' ',redirectTo:'/index',pathMath:'full' }
辅助路由:
<router-outlet name="yyy"></router-outlet>
{ path:'XXX',component:XXXComponent,outlet:'yyy'}
<a [routerLink]="['/XXX',{ outlets:{yyy:'XXX'} }]">XXX</a>