hberbary
hberbary

Reputation: 157

vue - How a normal link could act like <route-link>?

I have two pages routed:

Home > Results

Inside 'Home', I have a button/link which is not in <route-view/> and I want this button to redirect to Results.vue passing a parameter.

This parameter named activeTab, has to open the desired vue-tabs, which I can't accomplish, because it's getting nothing from variable:

code:

Home.vue

<div class="row">
     <Notes refName="Relationship" />
     <Notes refName="Support" />
</div>

...

<script>
import Notes from '@/components/Monthlynotes.vue'

export default {
     name: 'home',
     components: {
          Notes 
     },
</script>

/components/Monthlynotes.vue

<b-card>
     <p class="card-text">{{ refName }}</p>
     <b-link class="right" :activeTab="refName" href="/results">More</b-link>
</b-card>

...

<script>
export default {
  props: {
      refName: String,
  },          
</script>

Results.vue

 <vue-tabs type="pills" v-model="tabName">
   <v-tab title="Relationship">
     <RelDT msg="Results view"/>
   </v-tab>
   <v-tab title="Support">
     <SupDT msg="Results view"/>
   </v-tab>
 </vue-tabs>

...

<script>
import RelDT from '@/components/DataTable.rel.vue'
import SupDT from '@/components/DataTable.sup.vue'

export default {
  name: 'results',
  props: {
    activeTab: String
  },
  components:
    {
      RelDT,
      SupDT,
    },
  data() {
    return {
      tabName: activeTab
    }
  }
}
</script>

App

<router-link :to="{name:'results', param:{activeTab}}">Results</router-link>

How can I make this <b-link> route if it was a <route-link />?

Upvotes: 0

Views: 80

Answers (1)

Jns
Jns

Reputation: 3257

Even the b-link component supports the :to property. To be found here The value of the property will be passed to router.push().

<b-link :to="{name:'results', param:{activeTab}}">Redirect me</b-link>

Upvotes: 1

Related Questions