christo issac
christo issac

Reputation: 460

How can i pass active class through $router.push in Vue.js

I am using router-link for menu list. With that, active class is adding properly on clicking the link. I have a button in a page and it will navigate to another page using $router.push function but the active class is not removed from the previous page link and it is not added to navigated page.

btnClick: function () {
    this.$router.push({ path: '/NextPage' })
},

Can i force set active class through this.$router.push() function?

Upvotes: 1

Views: 1361

Answers (1)

Sunny Sheth
Sunny Sheth

Reputation: 101

Add linkActiveClass option while creating router object.

For e.g

const router = new VueRouter({ linkActiveClass: 'active' });

linkActiveClass is one of the route options.

https://router.vuejs.org/api/#name

Upvotes: 1

Related Questions