Use Component With VueRouter

Since the class decorated with Component is equivalent to Vue.extend({}) so you can just simply use it as routes component.

@Component({ template: '<div>This is foo!</div>' }) 
class Foo { }

@Component({ template: '<div>This is bar!</div>' }) 
class Bar { }

const routes = [
  { path: '/foo', component: Foo },
  { path: '/bar', component: Bar }
]

const router = new VueRouter({
  routes // short for routes: routes
})

new Vue({
  router
}).$mount('#app')

See live demo here or here.

results matching ""

    No results matching ""