The file structure should consists of -
It should consists of src folder containing store, components and assets as crucial elements to any vue boilerplate.
<router-view></router-view>
can be also written as <router-view/>
now onwards. It only displays the components that are included in routes.js
which is below app.vue
.
app.vue
<template>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header">
<header class="mdl-layout__header">
</header>
<div class="mdl-layout__drawer">
<nav class="mdl-navigation">
<router-link class="mdl-navigation__link" to="/" @click.native="hideMenu">Home</router-link>
<router-link class="mdl-navigation__link" to="/postview" @click.native="hideMenu">Post a picture</router-link>
</nav>
</div>
<main class="mdl-layout__content">
<div class="page-content">
<router-view></router-view>
</div>
</main>
</div>
</template>
routes.js can be in router folder in src, but here I have taken it in src folder as I don't have much to do with vue-router.
routes.js
import Vue from 'vue'
import Router from 'vue-router'
import homeview from '../components/homeview'
import detailview from '../components/detailview'
import postview from '../components/postview'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/',
name: 'Homeview',
component: homeview
},
{
path: '/detailview',
name: 'detailview',
component: detailview
},
{
path: '/postview',
name: 'Postview',
component: postview
}
]
})
main.js
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
Vue.config.productionTip = false
Vue.use(axios);
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
template: '<App/>',
components: { App }
})