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

angular2 Router类中的路由跳转navigate

发布时间:2020-12-17 10:39:20 所属栏目:安全 来源:网络整理
导读:navigate是Router类的一个方法,主要用来路由跳转。 函数定义 navigate(commands: any[],extras?: NavigationExtras) : Promise` ` 1. ; 以根路由为起点跳转 2. ; 默认值为根路由,设置后相对当前路由跳转,route是ActivatedRoute的实例,使用需要导入Activa

navigate是Router类的一个方法,主要用来路由跳转。

函数定义

navigate(commands: any[],extras?: NavigationExtras) : Promise``

1.;以根路由为起点跳转

2.;默认值为根路由,设置后相对当前路由跳转,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路由不会进行跳转

(编辑:李大同)

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

    推荐文章
      热点阅读