您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關(guān)Angular中怎么利用路由跳轉(zhuǎn)到指定頁面的指定位置,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
detail.component.html
<p>You'll see which payment methods are available to you on the checkout page, before you submit a reservation request. After you select your country, all of your payment details will be shown.</p> <p id="readMore">We charge featured guide who offer journey a 15% service fee. The amount of the service fee is calculated from the price that featured guide set for their journey. You will see the service fee when you set your price before submitting a journey. The service fee is automatically deducted from the payout to the Host. Depending on the laws of the jurisdiction involved, VAT may be charged on top of the service fee. The service fee will include these VAT charges when applicable.</p>
app.component.html
<button (click)="readMore()">ReadMore</button>
app.route.ts
{ path: '',component: LoginComponent}, { path: 'detail', component: DetailComponent }, { path: '**',component: NotFoundComponent}
方法一:新增路由地址來實現(xiàn)
app.route.ts
{ path: '',component: LoginComponent}, { path: 'detail', component: DetailComponent }, { path: 'detail#readMore',component: NotFoundComponent}, { path: '**',component: NotFoundComponent}
app.component.ts
readMore() { this.router.navigateByUrl('/detail#readMore'); }
detail.component.ts
ngOnInit() { if (window.location.hash === '#readMore') { window.location.assign('detail#readMore'); } }
方法二:在原路由地址不變的情況下,利用路由傳遞參數(shù)來實現(xiàn)
app.component.ts
readMore() { this.router.navigate(['/detail', { id: 'readMore'}]); } detail.component.ts this.myActivatedRoute.params.subscribe( (data: any) => { if (data.id === 'readMore') { window.location.assign('detail#readMore'); } } );
關(guān)于Angular中怎么利用路由跳轉(zhuǎn)到指定頁面的指定位置就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。