Skip to content

scrollBehavior shouldn't use window.scrollTo #1189

@TheDutchCoder

Description

@TheDutchCoder

Version

4.0.12

Reproduction link

stackblitz.com

Steps to reproduce

In the demo (sorry for the rough CSS), click on the "About link". It has a hash and the router has a scrollBehavior function that will log 'woops'.

Nothing will happen, even though the router is told to scroll down 200 pixels. This is because internally, the router uses window.scrollTo, which isn't correct. It should use .scrollTo on whatever element hosts the router view.

The body is set to not scroll, but the internal router-view div is.

In the console, use window.scrollTo(0, 200) and nothing will happen.
In the console, use document.querySelector('#wat').scrollTo(0, 200) and the view will properly scroll.

I think the router should select the proper view first, before attempting to scroll.

What is expected?

The view to scroll to the given position

What is actually happening?

Nothing is scrolling because window.scrollTo doesn't work when the body isn't scrollable.


I'm not sure how difficult this is, because this is heavily CSS dependent, but I think it should be doable to select the closest router-view of the element requested to scroll to?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions