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

Scroll-lock don't work when navigating back to a URL #478

Open
ferulisses opened this issue Sep 1, 2022 · 4 comments
Open

Scroll-lock don't work when navigating back to a URL #478

ferulisses opened this issue Sep 1, 2022 · 4 comments
Labels
bug Something isn't working needs triage

Comments

@ferulisses
Copy link

Description
When navigating in a page, a user will scroll looking for information.

When he finds and click a link, the user will open a new page (that he expects that will open in the top of the page as implemented here #31)

But, when clicking on back button (navigator back button or a provided back button from the application), the user expects to return to the place he has scrolled before.

Reproduce

  • Navigate to the example site, Widget examples:
    https://example.routify.dev/example/widget
  • Scroll down
  • Click on widget 9 or 10
  • New page will open with scroll on top, nice
  • Click back button on the page or Back button on web browser
  • Expected result: return to the position where I had scrolled before
  • Actual result: return to the top of the page Widgets

Fixes tried

<div data-routify="scroll-lock">
<div routify="scroll-lock">
  • I tried these code on the example/widget/_fallback.svelte and in example/_components/CrudWidget/_view.svelte

Other Info

  • @roxy/routify-2.18.7
  • svelte-3.49.0
@ferulisses ferulisses added bug Something isn't working needs triage labels Sep 1, 2022
@jakobrosenberg
Copy link
Member

There's currently no functionality for remembering scroll positions in history. Scroll lock has a different purpose. It prevents the whole page from scrolling to the top, which you sometimes need if you're navigating nested pages below the fold.

@ferulisses
Copy link
Author

Hum, understood. What is a good workaround? I'm thinking in save the current position in a store with BeforeURLChange and set it with AfterPageLoad, or is better to use afterNavigate?

I think that the browser keep the scroll position, at least in native HTML it does, if we could just turn off the scroll to Top, maybe it works. Or, at least, if it's possible to implement a goBack function that don't call scroll to Top, but I don't know if it's possible to know if the user clicked on the Back button of the web browser.

@jakobrosenberg
Copy link
Member

Hum, understood. What is a good workaround? I'm thinking in save the current position in a store with BeforeURLChange and set it with AfterPageLoad, or is better to use afterNavigate?

Those sound like good ideas. Couldn't tell which is best of the last two, maybe the former.

@jaeming
Copy link

jaeming commented Sep 8, 2022

I think I would also need to implement the desired behavior that @ferulisses describes here.
I'm migrating an app to Svelte from Vue + Vue-Router and it has this available through its scroll options.

I wonder is it something that could be achieved through the new plugin architecture in Routify 3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

3 participants