加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular 路由跳转以及传参

发布时间:2020-12-17 08:14:35 所属栏目:安全 来源:网络整理
导读:1 获取在路由后面的参数 a [routerLink]="['/list/nav','MALFUNCTION','WAITING']"/a 这种方式需要在路由配置像这样: { // 报修列表导航快捷栏 path : 'list/nav/:repairType/:repairStatus' ,}, 可以通过这种方式获取传递的参数: this . activatedRoute .

1 获取在路由后面的参数

<a [routerLink]="['/list/nav','MALFUNCTION','WAITING']"></a>

这种方式需要在路由配置像这样:

{
  // 报修列表导航快捷栏  path: 'list/nav/:repairType/:repairStatus',},
可以通过这种方式获取传递的参数:
this.activatedRoute.params['value']['repairType'];
通过这种方式传递参数域名是这样的:http://localhost:4200/#/system_manage/user/position/list/repairType/6
缺点: 不能通过
http://localhost:4200/#/system_manage/user/position/list/直接访问地址,必须的加上参数否则出错

2 通过域名跳转的方式获取参数(http://localhost:4200/#/system_manage/repair/list?repairType=REPAIR&repairStatus=WAITING)

这种方式不需要再路由后面配置,解放路由,只需跟平常一样写路由如:

{  path: "list",。。。。。。。。。。。。。
},255);font-family:'宋体';font-size:10.5pt;">只需要在ts代码中写地址跳转:
this.router.navigate(['/system_manage/repair/list'],{ queryParams: { 'repairType': 'CLEAN','repairStatus':'WAITING' } });
上面这种也可以传递多个参数
在comoent中需要这么获取‘?’ 后面的参数
this.activatedRoute.queryParams.subscribe((params:Params)=>{
    this.repairType = params['repairType'];
    this.repairStatus = params['repairStatus'];
});
这两种的方式获取传递参数的区别在于  
queryParamsthis.activatedRoute.params
 
 
 
 
 

再摘抄一些路由跳转的内容:

1.this.router.navigate(['user',1]);
以根路由为起点跳转

2.this.router.navigate(['user',1],{relativeTo: route});
默认值为根路由,设置后相对当前路由跳转,route是ActivatedRoute的实例,使用需要导入ActivatedRoute

3.this.router.navigate(['user',{ queryParams: { id: 1 } });
路由中传参数 /user/1?id=1

4.this.router.navigate(['view',{ preserveQueryParams: true });
默认值为false,设为true,保留之前路由中的查询参数/user?id=1 to /view?id=1

5.this.router.navigate(['user',{ 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',{ skipLocationChange: true });
默认值为false,设为true路由跳转时浏览器中的url是跳转前的路径,但是传入的参数依然有效

8.this.router.navigate(['/user',{ replaceUrl: true });未设置时默认为true,设置为false路由不会进行跳转

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读