pateketrueke / yrv

Your routing vibes! (for Svelte)
https://svelte.dev/repl/0f07c6134b16432591a9a3a0095a80de
161 stars 9 forks source link

Link: Scroll to top option? #16

Closed PiXy79 closed 4 years ago

PiXy79 commented 4 years ago

Hi, thank you for fixed the latest issues relating to babel and IE11 !!! I have only an issue, using your library. I'm using directly the Linkcomponent with only a href parameter. If I have a link at the bottom of a page/component, when I load the new route the scrollbar remains on bottom instead of positioning on top. Probably I'm missing something but there is a possibility to scroll on top after a route update, without reloading a page completely?

Thanks in advance !

gaou-piou commented 4 years ago

onMount(() => window.scrollTo(0, 0))

pateketrueke commented 4 years ago

Yeah, the previous suggestion would work but also you can subscribe to any route change:

import { router } from 'yrv';

router.subscribe(() => {
  window.scrollTo(0, 0);
});
PiXy79 commented 4 years ago

@pateketrueke Thanks, I have subscribed to any router change and it works perfectly.

frederikhors commented 4 years ago

@pateketrueke @PiXy79

Is it called two times when I first open the page, right?

pateketrueke commented 4 years ago

Is it called two times when I first open the page, right?

It can be called many times, it depends on the svelte reactivity tracking and your application state, etc.

But if you ask me it should fire when effective changes are made only, can you save a REPL to show the exact use-case you're describing?