0
votes

i have a home.vue component and inside the template i have multiple div’s with class names and ids and i have navigation links which i wanted to click and route to that certain div using the classnames or id’s is there anyway to do using vue-router ?

i tried out to use

 <li><router-link to="#about" >About Us</router-link></li>

for routing it to #aboutus id of the div but i cannot do it and i searched internet , didnt find any useful resource help me out . check out the imgur image here

1

1 Answers

1
votes

You don't need vue router for this. All you are doing is trying to scroll to a div on your page so why not try something like this:

<li>
   <a href="#" @click.prevent="goToDiv"><span>Go To</span></a>
</li>

and in your script:

methods: {
    goToDiv() {
      var elmnt = document.getElementById("yourId");
      elmnt.scrollIntoView();
    },
}