0

I have route like this:

{
    path: '/kontakt',
    redirect: '#contact',
    component: index
},

and scrollBehavior:

scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
        return savedPosition
    }
    if(!to.hash) {
        return {
            x: 0, y: 0
        }
    }
    if(to.hash) {
        return {
            selector: to.hash
        }
    }
}

and IMO because I display my page 1 second after user actually enter it (I show logo for 1sec) above code doesn't scroll page to #contact div when I enter /kontakt route.

app.vue

<div v-show="timeGap">
    <router-view />
</div>

here timeGap is changed to true after 1sec in setTimeout method. How to fix so it scroll to #contact div after this timeout?

BT101
  • 3,666
  • 10
  • 41
  • 90

1 Answers1

0

You have to move the control of your scrolling behaviour from your router scrollBehavior handler to your component index and there into the place that knows the logo show state is off.

This might be:

As soon as you find that place (watch) in your component you have to check if the logo state is off and do your scroll using this approach.

tony19
  • 125,647
  • 18
  • 229
  • 307
Valentine Shi
  • 6,604
  • 4
  • 46
  • 46