D
D
dark_king_132019-12-18 22:24:02
Vue.js
dark_king_13, 2019-12-18 22:24:02

How to keep active class in vue spa navigation after reload?

For me, there is a menuListItemActiveNumber variable which defaults to 0, when clicking on a link in the navigation, the value of the variable changes to the corresponding number. Depending on the value of the variable, the active class is assigned to a certain link. But after reloading the page, the active class is removed from the link, since menuListItemActiveNumber is again equal to 0. How can I fix this?
5dfa7c9f86aeb344056064.png
5dfa7cc46091d099093777.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Suha, 2019-12-18
@dark_king_13

it ?

B
be_a_man, 2019-12-19
@be_a_man

Use v-for and check for $route.path

ul.d-lg-flex(:class='{//...}')
  li(v-for='(item, index) in [['/Joury', 'Члены жюри'], ...]')
    router-link(:to='item[0]' :class='item[0] === $route.path && "is-active"' @click='change(index + 1)') {{item[1]}}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question