Praveen
Praveen

Reputation: 347

Vue.js - Unknown custom element: <router-view>

I'm bit new to Vue.js and I'm trying to implement routing to the application but for some reason I'm facing an issue saying:

Unknown custom element: <router-view> - did you register the component correctly? For recursive components, make sure to provide the "name" option

Am i registering the component wrongly? Any help is much appreciated, my code below:

app.js

import Vue from 'vue'
import AppLayout from './theme/Layout.vue'
import router from './router'

const app = new Vue({
  router,
  ...AppLayout
})

export { app, router }

router.js

import Vue from 'Vue'
import VueRouter from 'vue-router'
import Category from './theme/Category.vue'
import Login from './theme/Login.vue'

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    {path: '/', component: Category},
    {path: '/login', component: Login}
  ]
})

export default router

Layout.vue

 <template>
  <div>
    <app-header></app-header>
    <section class='main-section section'>
      <div class='container content'>
        <router-view></router-view>
      </div>
    </section>
    <app-footer></app-footer>
  </div>
</template>
<script>
import AppHeader from './AppHeader.vue'
import AppFooter from './AppFooter.vue'
export default {
  components: {
    'app-header': AppHeader,
    'app-footer': AppFooter
  }
}
</script>
<style lang='scss'>
$primary: #287ab1;
@import '~bulma';

</style>

I am following this guy's code Here and his course

Upvotes: 1

Views: 5392

Answers (1)

Daniel
Daniel

Reputation: 35684

Looks like Vue.use(VueRouter) is not doing its thing...

This is likely due to case sensitivity with your Vue import.

import Vue from 'Vue'  // <--- should be 'vue' NOT 'Vue'
import VueRouter from 'vue-router'
import Category from './theme/Category.vue'
import Login from './theme/Login.vue'

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    {path: '/', component: Category},
    {path: '/login', component: Login}
  ]
})

Upvotes: 3

Related Questions