S
S
shasoft2020-06-04 17:02:14
Vue.js
shasoft, 2020-06-04 17:02:14

Anchor navigation when using Vue Route?

I intercept the beforeRouteEnter/beforeRouteUpdate events, in it I load the page via ajax and write it to a variable and display it. But when following the anchor link, a problem arises: the page is successfully loaded and displayed, but the transition to the anchor does not occur.

Can anyone come across?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kuznetsov, 2020-06-04
@evgen3

I think it should be done like this:

beforeRouteEnter (to, from, next) {
  getData((data) => {
    next(vm => {
      vm.setData(data);
      vm.$nextTick(() => document.location.hash = '#anchor');
    });
  });
},

that is, we wait for data, we wait for drawing, we pass to the anchor

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question