Angular 利用路由跳转到指定页面的指定位置方法

前端之家收集整理的这篇文章主要介绍了Angular 利用路由跳转到指定页面的指定位置方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

之前做过页面内的跳转,比较简单,最近项目需要实现跨页面跳转,并跳转到指定地点,试了很多方法,有用到传递参数然后让页面滚动相应的距离,但是一旦文章长短发生变化,滚动的距离也需要重新计算,比较麻烦,所以最后总结出这两种比较靠谱的方法,只需要在需要跳转的地方加上合适的id就行,原理和单页面跳转相似。

detail.component.html

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.

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.

app.component.html

app.route.ts

方法一:新增路由地址来实现

app.route.ts

app.component.ts

detail.component.ts

方法二:在原路由地址不变的情况下,利用路由传递参数来实现

app.component.ts

this.myActivatedRoute.params.subscribe(
(data: any) => {
if (data.id === 'readMore') {
window.location.assign('detail#readMore');
}
}
);

以上这篇Angular 利用路由跳转指定页面的指定位置方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程之家。

原文链接:https://www.f2er.com/js/30575.html

猜你在找的JavaScript相关文章