Reputation: 2256
I have a very simple sample app with a tab control. I'd like either component A or component B to be displayed when a tab is selected. This should be handled by vue-router fairly easily but I don't know what's wrong with my config.
When I click on either tab button, nothing happens. None of my components display.
What am I missing?
import Vue from 'vue';
import {
Tabs,
} from 'buefy';
import 'buefy/dist/buefy.css';
import App from './App.vue';
import './registerServiceWorker';
import router from './router';
import store from './store';
Vue.use(Tabs);
Vue.config.productionTip = false;
new Vue({
router,
store,
render: (h) => h(App),
}).$mount('#app');
<template>
<div id="app">
<section>
<b-tabs type="is-toggle">
<b-tab-item label="Component A" to="/ComponentA"></b-tab-item>
<b-tab-item label="Component B" to="/ComponentB"></b-tab-item>
</b-tabs>
</section>
<router-view />
</div>
</template>
<style>
</style>
import Vue from 'vue';
import VueRouter from 'vue-router';
import ComponentA from '@/components/ComponentA.vue';
import ComponentB from '@/components/ComponentB.vue';
Vue.use(VueRouter);
const routes = [
{
path: '/ComponentB',
name: 'ComponentA',
component: ComponentA,
},
{
path: '/ComponentB',
name: 'ComponentB',
component: ComponentB,
},
];
const router = new VueRouter({
routes,
});
export default router;
<template>
<div>Hello From Component A</div>
</template>
<template>
<div>Hello From Component B</div>
</template>
Upvotes: 0
Views: 563
Reputation: 6209
I think this is an existing issue with Tabs & Router in Buefy. You could do something like this:
<b-tabs>
<router-link
label="Component A"
:to="{ name: 'ComponentA' }"
>
Component A
</router-link>
<router-link
label="Component B"
:to="{ name: 'ComponentB' }"
>
Component B
</router-link>
</b-tabs>
Or use a Buefy component that supports Vue Router, e.g:
<b-button tag="router-link" to="/ComponentA" type="is-link">
Component A
</b-button>
Upvotes: 1