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

小编给大家分享一下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参数跳转”有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!