您好,登錄后才能下訂單哦!
小編給大家分享一下javascript和Angular中如何使用Router.navigate的relativeTo參數(shù)跳轉(zhuǎn),希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
在使用this.router.navigate(['../'],{relativeTo:this.route})進(jìn)行路由跳轉(zhuǎn)時(shí),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()">進(jìn)入v2</a></p>
<p><ahref="javascript:void(0);"(click)="goV3()">進(jìn)入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});//沒反應(yīng)
}
看完了這篇文章,相信你對“javascript和Angular中如何使用Router.navigate的relativeTo參數(shù)跳轉(zhuǎn)”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。