国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

Angular 利用路由跳轉到指定頁面的指定位置方法

2024-05-06 15:30:51
字體:
來源:轉載
供稿:網友

之前做過頁面內的跳轉,比較簡單,最近項目需要實現跨頁面跳轉,并跳轉到指定地點,試了很多方法,有用到傳遞參數然后讓頁面滾動相應的距離,但是一旦文章長短發生變化,滾動的距離也需要重新計算,比較麻煩,所以最后總結出這兩種比較靠譜的方法,只需要在需要跳轉的地方加上合適的id就行,原理和單頁面內跳轉相似。

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.tsthis.myActivatedRoute.params.subscribe(  (data: any) => {  if (data.id === 'readMore') {   window.location.assign('detail#readMore');  }  } );

以上這篇Angular 利用路由跳轉到指定頁面的指定位置方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持錯新站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 甘洛县| 聂拉木县| 陇南市| 玛纳斯县| 易门县| 彭泽县| 新河县| 青岛市| 清远市| 万山特区| 公主岭市| 姜堰市| 如东县| 历史| 仁寿县| 建始县| 舒兰市| 军事| 玉环县| 大埔县| 鞍山市| 江口县| 长春市| 泰顺县| 武宁县| 宜丰县| 揭阳市| 新郑市| 吴川市| 夏邑县| 新化县| 忻城县| 晋江市| 慈溪市| 定州市| 凭祥市| 玛多县| 满城县| 灌云县| 庆元县| 枣庄市|