diff --git a/lib/app/pages/index.vue b/lib/app/pages/index.vue
new file mode 100644
index 0000000000..b308055207
--- /dev/null
+++ b/lib/app/pages/index.vue
@@ -0,0 +1,162 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/lib/builder/builder.js b/lib/builder/builder.js
index d7a11d75af..ee7cd6cbf9 100644
--- a/lib/builder/builder.js
+++ b/lib/builder/builder.js
@@ -119,9 +119,7 @@ export default class Builder {
`No \`${this.options.dir.pages}\` directory found in ${dir}. Did you mean to run \`nuxt\` in the parent (\`../\`) directory?`
)
} else {
- throw new Error(
- `Couldn't find a \`${this.options.dir.pages}\` directory in ${dir}. Please create one under the project root`
- )
+ this._defaultPage = true
}
}
}
@@ -249,8 +247,13 @@ export default class Builder {
// -- Routes --
consola.debug('Generating routes...')
- // If user defined a custom method to create routes
- if (this._nuxtPages) {
+
+ if (this._defaultPage) {
+ templateVars.router.routes = createRoutes(
+ ['index.vue'],
+ this.options.nuxtAppDir + '/pages'
+ )
+ } else if (this._nuxtPages) { // If user defined a custom method to create routes
// Use nuxt.js createRoutes bases on pages/
const files = {}
;(await glob(`${this.options.dir.pages}/**/*.{vue,js}`, {
diff --git a/test/unit/nuxt.test.js b/test/unit/nuxt.test.js
index 339692e41e..a3fdc2b402 100644
--- a/test/unit/nuxt.test.js
+++ b/test/unit/nuxt.test.js
@@ -1,5 +1,5 @@
import { resolve } from 'path'
-import { loadFixture, Nuxt, Builder } from '../utils'
+import { loadFixture, getPort, Nuxt, Builder } from '../utils'
describe('nuxt', () => {
test('Nuxt.js Class', () => {
@@ -32,16 +32,15 @@ describe('nuxt', () => {
})
})
- test('Fail to build when no pages/ directory', () => {
- const nuxt = new Nuxt({
- dev: false,
- rootDir: resolve(__dirname)
- })
+ test('Build with default page when no pages/ directory', async () => {
+ const nuxt = new Nuxt()
+ new Builder(nuxt).build()
+ const port = await getPort()
+ await nuxt.listen(port, 'localhost')
- return new Builder(nuxt).build().catch(err => {
- let s = String(err)
- expect(s.includes("Couldn't find a `pages` directory")).toBe(true)
- expect(s.includes('Please create one under the project root')).toBe(true)
- })
+ const { html } = await nuxt.renderRoute('/')
+ expect(html.includes('Universal Vue.js Applications')).toBe(true)
+
+ await nuxt.close()
})
})