$ cnpm install @nuxtjs/router-module
Nuxt module to use router.js instead of pages/ directory
The module features
@nuxtjs/router-module
dependency using yarn
or npm
to your project@nuxtjs/router-module
to modules
section of nuxt.config.js
{
modules: [
// Simple usage
'@nuxtjs/router-module',
// With options
['@nuxtjs/router-module', { /* module options */ }],
]
}
This module disable the pages/
directory into Nuxt and will use a router.js
file at your srcDir
directory:
components/
my-page.vue
router.js
router.js
need to export a createRouter
method like this:
import Vue from 'vue'
import Router from 'vue-router'
import MyPage from '~/components/my-page'
Vue.use(Router)
export function createRouter() {
return new Router({
mode: 'history',
routes: [
{
path: '/',
component: MyPage
}
]
})
}
Copyright (c) Sebastien Chopin seb@chopin.io
Copyright 2014 - 2017 © taobao.org |