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

查看:26
本文介绍了Angular 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

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

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