DDR爱好者之家 Design By 杰米
之前做过页面内的跳转,比较简单,最近项目需要实现跨页面跳转,并跳转到指定地点,试了很多方法,有用到传递参数然后让页面滚动相应的距离,但是一旦文章长短发生变化,滚动的距离也需要重新计算,比较麻烦,所以最后总结出这两种比较靠谱的方法,只需要在需要跳转的地方加上合适的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.ts this.myActivatedRoute.params.subscribe( (data: any) => { if (data.id === 'readMore') { window.location.assign('detail#readMore'); } } );
以上这篇Angular 利用路由跳转到指定页面的指定位置方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2024年04月19日
2024年04月19日
- 群星《中国摇滚历程》2CD[WAV分轨][3.2G]
- 张可儿《纯音HQCD》[正版原抓WAV+CUE]
- 群星【水月空禅心HQCD】最有禅意的笛箫演奏[正版CD原抓WAV+CUE]
- 迪克牛仔《我这个你不爱的人》台湾首版[WAV+CUE]
- 郑华娟.1995-旅途与岁月的纪念品(2013华纳复刻版)【飞碟】【WAV+CUE】
- 潘越云.1986-旧爱新欢【百佳唱片NO.31】【滚石】【WAV+CUE】
- 陈淑桦.1991-聪明糊涂心【滚石】【WAV+CUE】
- 魔兽世界PLUSP3阶段输出战士毕业装备 魔兽世界PLUSP3战士装备推荐
- dnf全部时装一览
- dnf公会频道为什么显示灰色
- 群星《好歌30年金曲典藏2CD》[正版CD原抓WAV+CUE]
- 九州方圆二十周年纪念唱片九州方圆歌声1984WAV+CUE
- 珍藏大碟《好歌30年全系列》双碟典藏版8CD[WAV/MP3/分轨]
- 群星《流行新歌告诉你》 2CD[WAV+CUE][1.5G]
- 群星《老情歌对对唱》3CD[WAV+CUE][1.5G]