@nuxtjs/router
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -6,3 +6,8 @@ 'use strict'; | ||
var index = function () { | ||
function index (options) { | ||
var defaults = { | ||
keepDefaultRouter: false | ||
}; | ||
options = Object.assign({}, defaults, options); | ||
var routerPath = path.resolve(this.options.srcDir, 'router.js'); | ||
@@ -13,6 +18,14 @@ | ||
// Disable parsing `pages/` | ||
this.nuxt.options.build.createRoutes = function () { | ||
return []; | ||
}; | ||
if (options.keepDefaultRouter) { | ||
// Put default router as .nuxt/defaultRouter.js | ||
this.addTemplate({ | ||
fileName: 'defaultRouter.js', | ||
src: require.resolve('nuxt/lib/app/router') | ||
}); | ||
} else { | ||
// Disable parsing `pages/` | ||
this.nuxt.options.build.createRoutes = function () { | ||
return []; | ||
}; | ||
} | ||
@@ -24,4 +37,5 @@ // Add ${srcDir}/router.js as the main template for routing | ||
}); | ||
}; | ||
} | ||
module.exports = index; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@nuxtjs/router", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Nuxt module to use router.js instead of pages/ directory", | ||
@@ -44,5 +44,6 @@ "license": "MIT", | ||
"devDependencies": { | ||
"jest-cli": "^21.0.2", | ||
"jest-cli": "^23.4.2", | ||
"nuxt": "^1.4.2", | ||
"nuxt-module-builder": "latest" | ||
} | ||
} |
# Nuxt Router Module | ||
[![npm (scoped with tag)](https://img.shields.io/npm/v/@nuxtjs/router-module/latest.svg?style=flat-square)](https://npmjs.com/package/@nuxtjs/router-module) | ||
[![npm](https://img.shields.io/npm/dt/@nuxtjs/router-module.svg?style=flat-square)](https://npmjs.com/package/@nuxtjs/router-module) | ||
[![npm (scoped with tag)](https://img.shields.io/npm/v/@nuxtjs/router/latest.svg?style=flat-square)](https://npmjs.com/package/@nuxtjs/router) | ||
[![npm](https://img.shields.io/npm/dt/@nuxtjs/router.svg?style=flat-square)](https://npmjs.com/package/@nuxtjs/router) | ||
[![CircleCI](https://img.shields.io/circleci/project/github/nuxt-community/router-module.svg?style=flat-square)](https://circleci.com/gh/nuxt-community/router-module) | ||
@@ -26,6 +26,28 @@ [![Codecov](https://img.shields.io/codecov/c/github/nuxt-community/router-module.svg?style=flat-square)](https://codecov.io/gh/nuxt-community/router-module) | ||
'@nuxtjs/router' | ||
] | ||
] | ||
} | ||
``` | ||
or | ||
```js | ||
{ | ||
modules: [ | ||
['@nuxtjs/router', { keepDefaultRouter: true }] | ||
] | ||
} | ||
``` | ||
3. If you are using SPA mode, add an index `/` route to `generate` section of `nuxt.config.js`: | ||
```js | ||
{ | ||
generate: { | ||
routes: [ | ||
'/' | ||
] | ||
} | ||
} | ||
``` | ||
## Usage | ||
@@ -64,2 +86,23 @@ | ||
### Accessing default router | ||
If you use the module with `{ keepDefaultRouter: true }`, you can access the default router: | ||
```js | ||
import { createRouter as createDefaultRouter } from './defaultRouter' | ||
export function createRouter(ssrContext) { | ||
const defaultRouter = createDefaultRouter(ssrContext) | ||
return new Router({ | ||
...defaultRouter.options, | ||
routes: fixRoutes(defaultRouter.options.routes) | ||
}) | ||
} | ||
function fixRoutes(defaultRoutes) { | ||
// default routes that come from `pages/` | ||
return defaultRoutes.filter(...).map(...) | ||
} | ||
``` | ||
## License | ||
@@ -66,0 +109,0 @@ |
import { resolve } from 'path' | ||
import { existsSync } from 'fs' | ||
export default function () { | ||
export default function (options) { | ||
const defaults = { | ||
keepDefaultRouter: false | ||
} | ||
options = Object.assign({}, defaults, options) | ||
const routerPath = resolve(this.options.srcDir, 'router.js') | ||
@@ -10,5 +15,13 @@ | ||
// Disable parsing `pages/` | ||
this.nuxt.options.build.createRoutes = () => { | ||
return [] | ||
if (options.keepDefaultRouter) { | ||
// Put default router as .nuxt/defaultRouter.js | ||
this.addTemplate({ | ||
fileName: 'defaultRouter.js', | ||
src: require.resolve('nuxt/lib/app/router') | ||
}) | ||
} else { | ||
// Disable parsing `pages/` | ||
this.nuxt.options.build.createRoutes = () => { | ||
return [] | ||
} | ||
} | ||
@@ -15,0 +28,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8340
7
61
111
3