V
V
Vlad2020-07-16 01:01:59
Vue.js
Vlad, 2020-07-16 01:01:59

Vue. How to put two routes on one button?

Hello. Let's say there is a layout, the content changes by replacing components, depending on which route.
At the very bottom of the layout there is a button "Continue"

<router-link tag="button" :to="{name: 'catalog', params: {module: 'view-1'}}">
Продолжить
</router-link>

Clicked and went to the catalog/view-1
url But how do I make it so that when I click again, it goes to module: 'view-2' ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2020-07-16
@Vlad024

Make the parameter value todependent on the current route:

computed: {
  catalogRoute() {
    return {
      name: 'catalog',
      params: {
        module: this.$route.name === 'catalog'
          ? this.$route.params.module.replace(/\d+/, m => +m + 1)
          : 'view-1',
      },
    };
  },
},

<router-link :to="catalogRoute">
https://jsfiddle.net/j6uh21cL/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question