2

I tried to implement VueJs with VueRouter. Home component is showing the log message but not the template part. And i got the following error:

enter image description here

Home.vue

<template>
    <div class="wrap" id="app">
        <h1 class="inline">Hello There</h1>
    </div>
</template>

<script>
export default {
    name: 'app',
    data () {
        return {
            maps: []
        }
    },
    mounted() {
        console.log( 'Mounted Homepage' );
    }
}
</script>

<style lang="scss">
#app {
   font-family: 'Avenir', Helvetica, Arial, sans-serif;
   -webkit-font-smoothing: antialiased;
   -moz-osx-font-smoothing: grayscale;
}
</style>

routes.js

import Vue from 'vue';
import Home from './components/Home.vue';
import NotFound from './components/NotFound.vue';

const routes = [
    { name: 'home', path: '/', components: Home },
    { path: '*', component: NotFound, meta: { title: 'Not Found' } }
];

import VueRouter from 'vue-router';
Vue.use(VueRouter);


var router = new VueRouter({
    routes
})

export default router;

Main.js

import Vue from 'vue'
import NotFound from './components/NotFound.vue'
import router from './routes'

new Vue({
    router,
    components: {
        NotFound
    }
}).$mount('#rgm_app');

Can you please let me know what i have missed?

1 Answer 1

15

you have a typo in this array declaration:

const routes = [
    { name: 'home', path: '/', components: Home },
    { path: '*', component: NotFound, meta: { title: 'Not Found' } }
];

just remove the extra s from components on the first object, and you should be ok.

Sign up to request clarification or add additional context in comments.

2 Comments

Seems a quite common miss. Typed so many components in .vue files and I cannot help to type another components in router file!
weirdly... this was my issue as well even though the use case and structure was completely different...

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.