0
I am learning Vue and came across a problem. I installed the vue-router
via npm
. When I call the <router-view>
, no error is indicated but the site does not render on the page. If I type the links in the address bar, the contents of the components are loaded.
main.js
import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './App.vue'
import {routes} from './routes'
Vue.use(VueRouter);
const router = new VueRouter({
routes
})
new Vue({
el: '#app',
router,
render: h => h(App)
})
Routes.js
import Contato from './components/Contato.vue'
import Sobre from './components/Sobre.vue'
import Home from './components/Home.vue'
export const routes = [
{path : '', component: Home},
{path : '/contato', component: Contato},
{path : '/sobre', component: Sobre}
]
App.
<template>
<div class="" id="app">
<div class="container">
<router-view></router-view>
</div>
</div>
</template>
<script>
export default {
}
</script>
<style lang="sass">
@import "~bulma/sass/utilities/initial-variables.sass"
@import "~bulma"
</style>
Has to be
path : '/'
instead ofpath : ''
– NoobSaibot
I fixed, but cotinuo with the same problem, In all the tutorials I saw it seemed to be so simple...
– Lucas Maraal
see now, I updated the answer with a much improved example, go ahead and just make the changes you need. :)
– NoobSaibot