角度6-路线更改时保持滚动位置 [英] Angular 6 - Keep scroll position when the route changes

查看:74
本文介绍了角度6-路线更改时保持滚动位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前的行为:

在导航到另一条路线时,更改路线或导航路径不会影响滚动位置.也就是说,内容可以更改,而滚动位置不会更改.

Changing the route or navigation path would not affect the scroll position when navigating to another route. I.e the contents can change without the scroll position changing.

当前行为:

更改路线将使您回到页面顶部.

Changing the route will put you right back to the top of the page.

到目前为止已完成的操作:

在最新和新的Angular 6项目中进行了测试

Tested on current and a fresh new Angular 6 project

这是一个错误吗?功能上的改变?还是有我缺少的参数.

Is this a bug? change in feature? or is there a parameter I am missing.

推荐答案

似乎将'scrollPositionRestoration'设置为禁用会对其进行修复

Seems like setting 'scrollPositionRestoration' to disabled fixes it

RouterModule.forRoot(
  appRoutes,
  { scrollPositionRestoration: 'disabled' } // <-- HERE
)

请参见 https://angular.io/api/router/ExtraOptions

这篇关于角度6-路线更改时保持滚动位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆