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

Switching pages after scrolled - end up at the top #31

Closed
Wolfr opened this issue Dec 26, 2019 · 9 comments
Closed

Switching pages after scrolled - end up at the top #31

Wolfr opened this issue Dec 26, 2019 · 9 comments

Comments

@Wolfr
Copy link
Collaborator

Wolfr commented Dec 26, 2019

If you switch pages on a website, you would expect to end up at the top (scroll position 0). This is currently not the case, the scroll position remains.

@Wolfr
Copy link
Collaborator Author

Wolfr commented Dec 26, 2019

Update - I fixed this with

    afterUpdate(() => {
        window.scrollTo(0, 0);
    });

Doesn't feel very clean but it works.

I wonder if setting scroll to 0,0 is part of other routing projects 🤔

@jakobrosenberg
Copy link
Member

You make a good point.

How about an afterNavigate hook?

<script>
  import { Router, afterNavigate } from "@sveltech/routify";
  import { routes } from "@sveltech/routify/tmp/routes";

  afterNavigate = () => window.scrollTo(0, 0) 
</script>

<Router {routes} />

It could also be a runtime option, though obviously less transparent and powerful.

@Wolfr
Copy link
Collaborator Author

Wolfr commented Dec 26, 2019

I don't see a reason why you wouldn't just lock it down in the framework. If the author wants to retain scroll position (can't come up with an example for this but hey, maybe someone else can), they could enable it. So 0,0 is the default; but you could opt out of that functionality if you have a reason to with a flag?

@jakobrosenberg
Copy link
Member

I guess we could create an autoScrollToTop and set it to true by default. This way, if anyone is so inclined, they have the option to opt out.

@jakobrosenberg
Copy link
Member

Should be fixed in the latest release.

@AlexanderBelkevich
Copy link

AlexanderBelkevich commented Feb 19, 2020

@jakobrosenberg This feature doesn't work on 1.0.1-53.
Maybe, I need to add something in my code?

@jakobrosenberg
Copy link
Member

@AlexanderBelkevich I'll have a look and get back to you.

@jakobrosenberg
Copy link
Member

@AlexanderBelkevich This has been fixed in 1.0.1-54.

@AlexanderBelkevich
Copy link

@jakobrosenberg Awesome! Now it's working :) Thank you)

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

No branches or pull requests

3 participants