Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native-like scroll behaviour when changing routes #1071

Closed
dcastil opened this issue Dec 5, 2018 · 2 comments · Fixed by #1075
Closed

Add native-like scroll behaviour when changing routes #1071

dcastil opened this issue Dec 5, 2018 · 2 comments · Fixed by #1075
Labels
contribution welcome Contributions welcome

Comments

@dcastil
Copy link
Contributor

dcastil commented Dec 5, 2018

Feature request

Currently the user stays at his current scroll position when the route is being changed. But when the user gets to a new page, he should see the top of the new page and when he goes back- and forward he should see the scroll position at which he left the page previously.

The logic on how the scroll position changes based on a route change should look like this:

  • New page → top scroll position
  • Already visited page → scroll position at which user previously left the page
  • Anchor change → scroll position at anchor

What problem does this feature solve?

  • The content of a page is ordered from top to bottom, so the top is what the user should see first when navigating to a page.
  • The user expects to be at the top of a page when the route changes, everything else can lead to confusion.

What does the proposed API look like?

The VuePress API doesn't change with this feature.

How should this be implemented in your opinion?

Vue Router provides a scrollBehavior API which can set the scroll position when changing routes. This could be implemented into the router initialisation in packages/@vuepress/core/lib/app/app.js.

The anchor scrolling doesn't need to be implemented as this is already solved, but maybe it's better to put everything into one place.

Are you willing to work on this yourself?

Yes, just want to check if this is desired.

@spiltcoffee
Copy link
Contributor

+1

Though, I would describe the current behavior as buggy rather than missing a feature 😛

@janvennemann
Copy link
Contributor

janvennemann commented Dec 5, 2018

This used to work but was changed in 5b0cdcf. @ulivz I'd be willing to work on this in case you aren't already working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome Contributions welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants