1

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

2
  • What happens when you change ...AppLayout to render: h => h(AppLayout)? Commented Mar 20, 2019 at 17:36
  • @Daniel same issue Commented Mar 20, 2019 at 17:39

1 Answer 1

3

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}
  ]
})
Sign up to request clarification or add additional context in comments.

3 Comments

spot on!, fresh set of eyes always helps, thank you very much for your time.
@Daniel: Why then Vue.use() did not cause an error?
I don't know ¯\_(ツ)_/¯

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.