javascript和Angular中如何使用Router.navigate的relativeTo参数跳转

发布时间:2021-09-23 09:23:51 作者:小新
来源:亿速云 阅读:156

小编给大家分享一下javascript和Angular中如何使用Router.navigate的relativeTo参数跳转,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

  在使用this.router.navigate(['../'],{relativeTo:this.route})进行路由跳转时,V1Component、V2Component都无法通过'../'、'../../'等方式回到上一级页面,而V3Component却可以,这是为什么呢?

  relativeto文件目录

  clipboard.png

  relativeto路由

  constroutes:Routes=[

  {path:'',redirectTo:'page',pathMatch:'full'},

  {

  path:'page',

  children:[

  {path:'',component:PageComponent},

  {

  path:'v1',

  children:[

  {path:'',component:V1Component},

  {

  path:'v2',

  children:[

  {path:'',component:V2Component},

  {path:'v3',component:V3Component}

  ]

  }

  ]

  },

  ]

  }

  ];

  v1

  <p>我是v1</p>

  <p><ahref="javascript:void(0);"(click)="goV2()">进入v2</a></p>

  <p><ahref="javascript:void(0);"(click)="goV3()">进入v3</a></p>

  <p><ahref="javascript:void(0);"(click)="backPage()">回到page</a></p>

  goV2(){

  this.router.navigate(['v2'],{relativeTo:this.route});

  }

  goV3(){

  this.router.navigate(['v2/v3'],{relativeTo:this.route});

  }

  backPage(){

  this.router.navigate(['../'],{relativeTo:this.route});//没反应

  }

看完了这篇文章,相信你对“javascript和Angular中如何使用Router.navigate的relativeTo参数跳转”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

推荐阅读:
  1. nginx带参数跳转
  2. 怎么使用html中的页面跳转传递参数

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

javascript angular router

上一篇:c++中如何使用static_cast转换

下一篇:MYSQL中视图怎么用

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》