您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關Angular中怎么利用路由跳轉到指定頁面的指定位置,文章內容質量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關知識有一定的了解。
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}
方法一:新增路由地址來實現
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'); } }
方法二:在原路由地址不變的情況下,利用路由傳遞參數來實現
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'); } } );
關于Angular中怎么利用路由跳轉到指定頁面的指定位置就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。