ppppp
ppppp

Reputation: 13

my component's contents are not being displayed when I use vue-router

I am new to vue. Sorry if this is a silly question. I am using vue-router to route to a component. My url is changing when I click on the router link but the contents of the component are not being displayed. I am not getting any error in the developer tools. It would be a huge help if you can help.

I tried all the answers regarding this issue here and still couldn't get it to work.

src/App.vue

<template>
  <div id="app">
    <router-link to="/toread">Go toread</router-link>
    <router-view></router-view>
  </div>
</template>
<script>
import toread from './components/toread.vue';
export default {
  name: 'app',
  components:{
    toread
  },
}
</script>

src/components/toread.vue

<template>
    <div>
        <h1>toread</h1>
    </div>
</template>
<script>
export default {

}
</script>
<style scoped>

</style>

src/main.js

import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import Routes from './routes'
import toread from './components/toread.vue'

Vue.use(VueRouter)
const router = new VueRouter({
  Routes
});
new Vue({
  el: '#app',
  render: h => h(App),
  router
})

src/routes.js

import toread from './components/toread.vue'
export default[
    {path:'/toread', component:toread},
]

I expect to click on the router link and display the h1 tag from toread component.

Upvotes: 1

Views: 59

Answers (1)

Sajib Khan
Sajib Khan

Reputation: 24156

Change Routes to routes: Routes

const router = new VueRouter({
  routes: Routes
});

Upvotes: 1

Related Questions