diff --git a/examples/custom-layouts/README.md b/examples/custom-layouts/README.md new file mode 100644 index 0000000000..a829a56d85 --- /dev/null +++ b/examples/custom-layouts/README.md @@ -0,0 +1,60 @@ +# Layouts + +> Nuxt.js allows you to extend the main layout or create custom layout by adding them in the `layouts/` directory + +## layouts/default.vue + +You can extend the main layout by adding a `layouts/default.vue` file. + +*Make sure to add the `` component when creating a layout to display the page component.* + +The default layout source code is: +```html + +``` + +## layouts/error.vue + +You can customize the error page by adding a `layouts/error.vue` file. + +This layout is special since your should not include `` inside its template, see this layout as a component displayed when an error occurs (404, 500, etc). + +The default error page source code is available on: https://github.com/nuxt/nuxt.js/blob/master/lib/app/components/nuxt-error.vue + +## layouts/*.vue + +See the [demonstration video](https://www.youtube.com/watch?v=YOKnSTp7d38). + +Every file (*first level*) in the `layouts/` directory will create a custom layout accessible with the `layout` property in the page component. + +*Make sure to add the `` component when creating a layout to display the page component.* + +Example of `layouts/blog.vue`: +```html + +``` + +And then in `pages/posts.vue` I can tell Nuxt.js to use this custom layout: +```html + +``` + +## Demo + +```bash +npm install +npm run dev +``` + +Go to [http://localhost:3000](http://localhost:3000) and navigate trough the app. To see the custom error page: [http://localhost:3000/404](http://localhost:3000/404) diff --git a/examples/custom-layouts/layouts/dark.vue b/examples/custom-layouts/layouts/dark.vue new file mode 100644 index 0000000000..5c3d13f4f4 --- /dev/null +++ b/examples/custom-layouts/layouts/dark.vue @@ -0,0 +1,21 @@ + + + diff --git a/examples/extend-app/layouts/app.vue b/examples/custom-layouts/layouts/default.vue similarity index 80% rename from examples/extend-app/layouts/app.vue rename to examples/custom-layouts/layouts/default.vue index a07eda60e8..fd88fdc3d1 100644 --- a/examples/extend-app/layouts/app.vue +++ b/examples/custom-layouts/layouts/default.vue @@ -1,8 +1,8 @@ diff --git a/examples/extend-app/package.json b/examples/custom-layouts/package.json similarity index 81% rename from examples/extend-app/package.json rename to examples/custom-layouts/package.json index ce5d6af2a6..4b5f4b7874 100644 --- a/examples/extend-app/package.json +++ b/examples/custom-layouts/package.json @@ -1,5 +1,5 @@ { - "name": "nuxt-extend-app", + "name": "nuxt-custom-layouts", "dependencies": { "nuxt": "latest" }, diff --git a/examples/extend-app/pages/about.vue b/examples/custom-layouts/pages/about.vue similarity index 77% rename from examples/extend-app/pages/about.vue rename to examples/custom-layouts/pages/about.vue index 7ed044bcba..92d592b225 100644 --- a/examples/extend-app/pages/about.vue +++ b/examples/custom-layouts/pages/about.vue @@ -7,9 +7,10 @@ + +<% css.forEach(function (c) { %> + +<% }) %> diff --git a/lib/app/client.js b/lib/app/client.js index 8f01a7dd13..13409b560c 100644 --- a/lib/app/client.js +++ b/lib/app/client.js @@ -58,75 +58,88 @@ function loadAsyncComponents (to, ___, next) { function render (to, from, next) { let Components = getMatchedComponents(to) if (!Components.length) { - this.error({ statusCode: 404, message: 'This page could not be found.', url: to.path }) - return next() + // Default layout + this.setLayout() + .then(() => { + this.error({ statusCode: 404, message: 'This page could not be found.', url: to.path }) + return next() + }) + return } // Update ._data and other properties if hot reloaded Components.forEach(function (Component) { if (!Component._data) { Component._data = Component.options.data || noopData } - if (Component._Ctor && Component._Ctor.options && Component._dataFn) { + if (Component._Ctor && Component._Ctor.options) { Component.options.fetch = Component._Ctor.options.fetch - const originalDataFn = Component._data.toString().replace(/\s/g, '') - const dataFn = Component._dataFn - const newDataFn = (Component._Ctor.options.data || noopData).toString().replace(/\s/g, '') - // If component data method changed - if (newDataFn !== originalDataFn && newDataFn !== dataFn) { - Component._data = Component._Ctor.options.data || noopData + if (Component._dataFn) { + const originalDataFn = Component._data.toString().replace(/\s/g, '') + const dataFn = Component._dataFn + const newDataFn = (Component._Ctor.options.data || noopData).toString().replace(/\s/g, '') + // If component data method changed + if (newDataFn !== originalDataFn && newDataFn !== dataFn) { + Component._data = Component._Ctor.options.data || noopData + } } } }) this.setTransitions(mapTransitions(Components, to, from)) this.error() let nextCalled = false - let isValid = true - Components.forEach((Component) => { - if (!isValid) return - if (typeof Component.options.validate !== 'function') return - isValid = Component.options.validate({ - params: to.params || {}, - query: to.query || {} - }) - }) - if (!isValid) { - this.error({ statusCode: 404, message: 'This page could not be found.', url: to.path }) - return next() - } - Promise.all(Components.map((Component, i) => { - // Check if only children route changed - Component._path = compile(to.matched[i].path)(to.params) - if (Component._path === _lastPaths[i] && (i + 1) !== Components.length) { - return Promise.resolve() - } - let promises = [] - const _next = function (path) { - <%= (loading ? 'this.$loading.finish && this.$loading.finish()' : '') %> - nextCalled = true - next(path) - } - const context = getContext({ to<%= (store ? ', store' : '') %>, isClient: true, next: _next.bind(this), error: this.error.bind(this) }) - // Validate method - if (Component._data && typeof Component._data === 'function') { - var promise = promisify(Component._data, context) - promise.then((data) => { - Component.options.data = () => data || {} - Component._dataFn = Component.options.data.toString().replace(/\s/g, '') - if (Component._Ctor && Component._Ctor.options) { - Component._Ctor.options.data = Component.options.data - } - <%= (loading ? 'this.$loading.increase && this.$loading.increase(30)' : '') %> + // Set layout + this.setLayout(Components[0].options.layout) + .then(() => { + // Pass validation? + let isValid = true + Components.forEach((Component) => { + if (!isValid) return + if (typeof Component.options.validate !== 'function') return + isValid = Component.options.validate({ + params: to.params || {}, + query: to.query || {} }) - promises.push(promise) + }) + if (!isValid) { + this.error({ statusCode: 404, message: 'This page could not be found.', url: to.path }) + return next() } - if (Component.options.fetch) { - var p = Component.options.fetch(context) - if (!(p instanceof Promise)) { p = Promise.resolve(p) } - <%= (loading ? 'p.then(() => this.$loading.increase && this.$loading.increase(30))' : '') %> - promises.push(p) - } - return Promise.all(promises) - })) + return Promise.all(Components.map((Component, i) => { + // Check if only children route changed + Component._path = compile(to.matched[i].path)(to.params) + if (Component._path === _lastPaths[i] && (i + 1) !== Components.length) { + return Promise.resolve() + } + let promises = [] + const _next = function (path) { + <%= (loading ? 'this.$loading.finish && this.$loading.finish()' : '') %> + nextCalled = true + next(path) + } + const context = getContext({ to<%= (store ? ', store' : '') %>, isClient: true, next: _next.bind(this), error: this.error.bind(this) }) + // Validate method + if (Component._data && typeof Component._data === 'function') { + var promise = promisify(Component._data, context) + promise.then((data) => { + Component._cData = () => data || {} + Component.options.data = Component._cData + Component._dataFn = Component.options.data.toString().replace(/\s/g, '') + if (Component._Ctor && Component._Ctor.options) { + Component._Ctor.options.data = Component.options.data + } + <%= (loading ? 'this.$loading.increase && this.$loading.increase(30)' : '') %> + }) + promises.push(promise) + } + if (Component.options.fetch) { + var p = Component.options.fetch(context) + if (!(p instanceof Promise)) { p = Promise.resolve(p) } + <%= (loading ? 'p.then(() => this.$loading.increase && this.$loading.increase(30))' : '') %> + promises.push(p) + } + return Promise.all(promises) + })) + }) .then(() => { _lastPaths = Components.map((Component, i) => compile(to.matched[i].path)(to.params)) <%= (loading ? 'this.$loading.finish && this.$loading.finish()' : '') %> @@ -157,11 +170,13 @@ function fixPrepatch (to, ___) { } return instance.constructor.options.__file }) + hotReloadAPI(this) }) } // Special hot reload with data(context) function hotReloadAPI (_app) { + if (!module.hot) return const $nuxt = _app.$nuxt var _forceUpdate = $nuxt.$forceUpdate.bind($nuxt) $nuxt.$forceUpdate = function () { @@ -173,6 +188,14 @@ function hotReloadAPI (_app) { Component._Ctor = Component } let promises = [] + // If layout changed + if (_app.layoutName !== Component.options.layout) { + let promise = _app.setLayout(Component.options.layout) + promise.then(() => { + hotReloadAPI(_app) + }) + promises.push(promise) + } const next = function (path) { <%= (loading ? 'this.$loading.finish && this.$loading.finish()' : '') %> router.push(path) @@ -185,12 +208,16 @@ function hotReloadAPI (_app) { Component._data = Component._Ctor.options.data || noopData let p = promisify(Component._data, context) p.then((data) => { - Component.options.data = () => data || {} + Component._cData = () => data || {} + Component.options.data = Component._cData Component._dataFn = Component.options.data.toString().replace(/\s/g, '') Component._Ctor.options.data = Component.options.data <%= (loading ? 'this.$loading.increase && this.$loading.increase(30)' : '') %> }) promises.push(p) + } else if (Component._cData) { + Component.options.data = Component._cData + Component._Ctor.options.data = Component.options.data } // Check if fetch has been updated const originalFetchFn = (Component.options.fetch || noopFetch).toString().replace(/\s/g, '') @@ -233,7 +260,8 @@ const resolveComponents = flatMapComponents(router.match(path), (Component, _, m if (Component.options.data && typeof Component.options.data === 'function') { Component._data = Component.options.data if (NUXT.serverRendered) { - Component.options.data = () => NUXT.data[index] || {} + Component._cData = () => NUXT.data[index] || {} + Component.options.data = Component._cData Component._dataFn = Component.options.data.toString().replace(/\s/g, '') } if (Component._Ctor && Component._Ctor.options) { @@ -264,6 +292,13 @@ function nuxtReady (app) { Promise.all(resolveComponents) .then((Components) => { const _app = new Vue(app) + + return _app.setLayout(Components.length ? Components[0].options.layout : '') + .then(() => { + return { _app, Components } + }) +}) +.then(({ _app, Components }) => { const mountApp = () => { _app.$mount('#__nuxt') <% if (loading) { %> @@ -271,7 +306,7 @@ Promise.all(resolveComponents) _app.$loading = _app.$nuxt.$loading <% } %> // Hot reloading - if (module.hot) hotReloadAPI(_app) + hotReloadAPI(_app) // Call window.onNuxtReady callbacks Vue.nextTick(() => nuxtReady(_app)) } diff --git a/lib/app/components/nuxt-container.vue b/lib/app/components/nuxt-container.vue deleted file mode 100644 index e351bf3c5c..0000000000 --- a/lib/app/components/nuxt-container.vue +++ /dev/null @@ -1,16 +0,0 @@ - - - - -<% css.forEach(function (c) { %> - -<% }) %> diff --git a/lib/app/components/nuxt.vue b/lib/app/components/nuxt.vue index 743984a1b7..759103073a 100644 --- a/lib/app/components/nuxt.vue +++ b/lib/app/components/nuxt.vue @@ -22,6 +22,8 @@ export default { Vue.prototype.$nuxt = this // Add this.$root.$nuxt this.$root.$nuxt = this + // Bind $nuxt.setLayout(layout) to $root.setLayout + this.setLayout = this.$root.setLayout.bind(this.$root) // add to window so we can listen when ready if (typeof window !== 'undefined') { window.$nuxt = this diff --git a/lib/app/index.js b/lib/app/index.js index 7e6eba54f9..64eba583f1 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -4,14 +4,11 @@ import Vue from 'vue' import Meta from 'vue-meta' import router from './router.js' <% if (store) { %>import store from '~store/index.js'<% } %> -import NuxtContainer from './components/nuxt-container.vue' import NuxtChild from './components/nuxt-child.js' import NuxtLink from './components/nuxt-link.js' import Nuxt from './components/nuxt.vue' import App from '<%= appPath %>' -// Component: -Vue.component(NuxtContainer.name, NuxtContainer) // Component: Vue.component(NuxtChild.name, NuxtChild) // Component: diff --git a/lib/app/layouts/default.vue b/lib/app/layouts/default.vue new file mode 100644 index 0000000000..2cc8469e52 --- /dev/null +++ b/lib/app/layouts/default.vue @@ -0,0 +1,3 @@ + diff --git a/lib/app/server.js b/lib/app/server.js index c458729d5d..0a6704de44 100644 --- a/lib/app/server.js +++ b/lib/app/server.js @@ -73,6 +73,10 @@ export default context => { } return Component }) + // Set layout + return _app.setLayout(Components.length ? Components[0].options.layout : '') + }) + .then(() => { // Call .validate() let isValid = true Components.forEach((Component) => { diff --git a/lib/build/index.js b/lib/build/index.js index 8d47588799..4e7a8f15dc 100644 --- a/lib/build/index.js +++ b/lib/build/index.js @@ -132,6 +132,14 @@ function * buildFiles () { function * generateRoutesAndFiles () { debug('Generating routes...') + // Layouts + let layouts = {} + const layoutsFiles = yield glob('layouts/*.vue', { cwd: this.srcDir }) + layoutsFiles.forEach((file) => { + let name = file.split('/').slice(-1)[0].replace('.vue', '') + if (name === 'error') return + layouts[name] = r(this.srcDir, file) + }) // Generate routes based on files const files = yield glob('pages/**/*.vue', { cwd: this.srcDir }) this.routes = _.uniq(_.map(files, (file) => { @@ -146,7 +154,6 @@ function * generateRoutesAndFiles () { 'router.js', 'server.js', 'utils.js', - 'components/nuxt-container.vue', 'components/nuxt-loading.vue', 'components/nuxt-child.js', 'components/nuxt-link.js', @@ -165,6 +172,7 @@ function * generateRoutesAndFiles () { css: this.options.css, plugins: this.options.plugins.map((p) => r(this.srcDir, p)), appPath: './App.vue', + layouts: layouts, loading: (typeof this.options.loading === 'string' ? r(this.srcDir, this.options.loading) : this.options.loading), transition: this.options.transition, components: { @@ -174,12 +182,15 @@ function * generateRoutesAndFiles () { } // Format routes for the lib/app/router.js template templateVars.router.routes = createRoutes(files, this.srcDir) - if (fs.existsSync(join(this.srcDir, 'layouts', 'app.vue'))) { - templateVars.appPath = r(this.srcDir, 'layouts/app.vue') - } - if (fs.existsSync(join(this.srcDir, 'layouts', 'error.vue'))) { + if (layoutsFiles.includes('layouts/error.vue')) { templateVars.components.ErrorPage = r(this.srcDir, 'layouts/error.vue') } + // If no default layout, create its folder and add the default folder + if (!layouts.default) { + yield mkdirp(r(this.dir, '.nuxt/layouts')) + templatesFiles.push('layouts/default.vue') + layouts.default = r(__dirname, 'app', 'layouts', 'default.vue') + } let moveTemplates = templatesFiles.map((file) => { return readFile(r(__dirname, 'app', file), 'utf8') .then((fileContent) => { @@ -347,7 +358,14 @@ function createRenderer (bundle) { } function watchPages () { - const patterns = [ r(this.srcDir, 'pages/*.vue'), r(this.srcDir, 'pages/**/*.vue') ] + const patterns = [ + r(this.srcDir, 'pages'), + r(this.srcDir, 'pages/*.vue'), + r(this.srcDir, 'pages/**/*.vue'), + r(this.srcDir, 'layouts'), + r(this.srcDir, 'layouts/*.vue'), + r(this.srcDir, 'layouts/**/*.vue') + ] const options = { ignoreInitial: true } diff --git a/package.json b/package.json index f25f09daca..e188675699 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ }, "dependencies": { "ansi-html": "^0.0.6", - "autoprefixer": "^6.5.4", + "autoprefixer": "^6.6.0", "babel-core": "^6.21.0", "babel-loader": "^6.2.10", "babel-polyfill": "^6.20.0", @@ -55,7 +55,7 @@ "co": "^4.6.0", "cross-spawn": "^5.0.1", "css-loader": "^0.26.1", - "debug": "^2.4.5", + "debug": "^2.5.1", "es6-object-assign": "^1.0.3", "es6-promise": "^4.0.5", "extract-text-webpack-plugin": "2.0.0-beta.4", @@ -64,7 +64,7 @@ "glob": "^7.1.1", "hash-sum": "^1.0.2", "html-minifier": "^3.2.3", - "lodash": "^4.17.2", + "lodash": "^4.17.3", "lru-cache": "^4.0.2", "memory-fs": "^0.4.1", "path-to-regexp": "^1.7.0", @@ -72,16 +72,16 @@ "serialize-javascript": "^1.3.0", "serve-static": "^1.11.1", "url-loader": "^0.5.7", - "vue": "^2.1.6", + "vue": "^2.1.7", "vue-loader": "^10.0.2", "vue-meta": "^0.5.3", "vue-router": "^2.1.1", - "vue-server-renderer": "^2.1.6", - "vue-template-compiler": "^2.1.6", + "vue-server-renderer": "^2.1.7", + "vue-template-compiler": "^2.1.7", "vuex": "^2.1.1", - "webpack": "2.2.0-rc.1", + "webpack": "2.2.0-rc.2", "webpack-dev-middleware": "^1.9.0", - "webpack-hot-middleware": "^2.13.2" + "webpack-hot-middleware": "^2.14.0" }, "devDependencies": { "ava": "^0.17.0", diff --git a/test/dynamic-routes.test.js b/test/dynamic-routes.test.js new file mode 100644 index 0000000000..3e9e47b87f --- /dev/null +++ b/test/dynamic-routes.test.js @@ -0,0 +1,51 @@ +import test from 'ava' +import { resolve } from 'path' +import fs from 'fs' +import pify from 'pify' +const readFile = pify(fs.readFile) + +// Init nuxt.js and create server listening on localhost:4000 +test.before('Init Nuxt.js', async t => { + const Nuxt = require('../') + const nuxt = new Nuxt({ + rootDir: resolve(__dirname, 'fixtures/dynamic-routes'), + dev: false + }) + await nuxt.build() +}) + +test('Check .nuxt/router.js', t => { + return readFile(resolve(__dirname, './fixtures/dynamic-routes/.nuxt/router.js'), 'utf-8') + .then((routerFile) => { + routerFile = routerFile.slice( + routerFile.indexOf('routes: ['), + -3 + ) + .replace('routes: [', '[') + .replace(/ _[0-9A-z]+,/g, ' "",') + let routes = eval('( ' + routerFile + ')') // eslint-disable-line no-eval + // pages/test/index.vue + t.is(routes[0].path, '/test') + t.is(routes[0].name, 'test') + // pages/parent.vue + t.is(routes[1].path, '/parent') + t.falsy(routes[1].name) // parent route has no name + // pages/parent/*.vue + t.is(routes[1].children.length, 3) // parent has 3 children + t.deepEqual(routes[1].children.map((r) => r.path), ['', 'teub', 'child']) + t.deepEqual(routes[1].children.map((r) => r.name), ['parent', 'parent-teub', 'parent-child']) + // pages/test/users.vue + t.is(routes[2].path, '/test/users') + t.falsy(routes[2].name) // parent route has no name + // pages/test/users/*.vue + t.is(routes[2].children.length, 3) // parent has 3 children + t.deepEqual(routes[2].children.map((r) => r.path), ['', ':id', ':index/teub']) + t.deepEqual(routes[2].children.map((r) => r.name), ['test-users', 'test-users-id', 'test-users-index-teub']) + // pages/_slug.vue + t.is(routes[3].path, '/:slug?') + t.is(routes[3].name, 'slug') + // pages/_key/_id.vue + t.is(routes[4].path, '/:key?/:id?') + t.is(routes[4].name, 'key-id') + }) +}) diff --git a/test/fixtures/dynamic-routes/README.md b/test/fixtures/dynamic-routes/README.md deleted file mode 100644 index a6a85d97ad..0000000000 --- a/test/fixtures/dynamic-routes/README.md +++ /dev/null @@ -1,185 +0,0 @@ -# Defining custom routes with Nuxt.js - -> Nuxt.js is based on `vue-router` and let you to defined custom routes easily :rocket: - -## Concept - -Nuxt.js generates automatically the `vue-router` configuration according to your file tree of `.vue` files inside the `pages/` directory. - -## Basic routes - -This file tree: - -```bash -pages/ ---| team/ ------| index.vue ------| about.vue ---| index.vue -``` - -will automatically generate: - -```js -router: { - routes: [ - { - name: 'index', - path: '/', - component: 'pages/index.vue' - }, - { - name: 'team', - path: '/team', - component: 'pages/team/index.vue' - }, - { - name: 'team-about', - path: '/team/about', - component: 'pages/team/about.vue' - } - ] -} -``` - -## Dynamic routes - -To define a dynamic route with a param, you need to define a `.vue` file **prefixed by an underscore**. - -This file tree: - -```bash -pages/ ---| users/ ------| _id.vue ------| index.vue -``` - -will automatically generate: - -```js -router: { - routes: [ - { - name: 'users', - path: '/users', - component: 'pages/users/index.vue' - }, - { - name: 'users-id', - path: '/users/:id', - component: 'pages/users/_id.vue' - } - ] -} -``` - -### Additional feature: validate (optional) - -Nuxt.js lets you define a validator function inside your dynamic route component (In this example: `pages/users/_id.vue`). - -If the validate method does not return `true`, Nuxt.js will automatically load the 404 error page. - -```js - -``` - -## Nested Routes (children) - -To define a nested route, you need to create a `.vue` file with the **same name as the directory** which contain your children views. -> Don't forget to put `` inside your parent `.vue` file. - -This file tree: - -```bash -pages/ ---| users/ ------| _id.vue ---| users.vue -``` - -will automatically generate: - -```js -router: { - routes: [ - { - path: '/users', - component: 'pages/users.vue', - children: [ - { - path: ':id', - component: 'pages/users/_id.vue', - name: 'users-id' - } - ] - } - ] -} -``` - -## Dynamic Nested Routes - -This file tree: - -```bash -pages/ ---| posts/ ------| _slug/ ---------| _name.vue ---------| comments.vue ------| _slug.vue ------| index.vue ---| posts.vue -``` - -will automatically generate: - -```js -router: { - routes: [ - { - path: '/posts', - component: 'pages/posts.vue', - children: [ - { -          path '', - component: 'pages/posts/index.vue', - name: 'posts' - }, - { - path: ':slug', - component: 'pages/posts/_slug.vue', - children: [ - { - path: 'comments', - component: 'pages/posts/_slug/comments.vue', - name: 'posts-slug-comments' - }, - { - path: ':name', - component: 'pages/posts/_slug/_name.vue', - name: 'posts-slug-name' - } - ] - } - ] - } - ] -} -``` - -## Demo - -```bash -npm install -npm start -``` - -Go to [http://localhost:3000](http://localhost:3000) and navigate through the pages. diff --git a/test/fixtures/dynamic-routes/nuxt.config.js b/test/fixtures/dynamic-routes/nuxt.config.js deleted file mode 100644 index bb0765f744..0000000000 --- a/test/fixtures/dynamic-routes/nuxt.config.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - build: { - vendor: ['axios'] - } -} diff --git a/test/fixtures/dynamic-routes/package.json b/test/fixtures/dynamic-routes/package.json deleted file mode 100644 index 31c9724fdb..0000000000 --- a/test/fixtures/dynamic-routes/package.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "nuxt-custom-routes", - "description": "", - "dependencies": { - "axios": "^0.15.2", - "nuxt": "latest" - }, - "scripts": { - "dev": "nuxt", - "build": "nuxt build", - "start": "nuxt start" - } -} diff --git a/test/fixtures/dynamic-routes/pages/test/index.vue b/test/fixtures/dynamic-routes/pages/test/index.vue index 94414546d1..e69de29bb2 100644 --- a/test/fixtures/dynamic-routes/pages/test/index.vue +++ b/test/fixtures/dynamic-routes/pages/test/index.vue @@ -1,46 +0,0 @@ - - - - - diff --git a/test/fixtures/dynamic-routes/pages/test/users/_id.vue b/test/fixtures/dynamic-routes/pages/test/users/_id.vue index ccd6594097..e69de29bb2 100644 --- a/test/fixtures/dynamic-routes/pages/test/users/_id.vue +++ b/test/fixtures/dynamic-routes/pages/test/users/_id.vue @@ -1,33 +0,0 @@ - - - - - diff --git a/test/fixtures/with-config/layouts/app.vue b/test/fixtures/with-config/layouts/app.vue deleted file mode 100644 index 25fab4ce30..0000000000 --- a/test/fixtures/with-config/layouts/app.vue +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/test/fixtures/with-config/layouts/custom.vue b/test/fixtures/with-config/layouts/custom.vue new file mode 100644 index 0000000000..44d4c1721f --- /dev/null +++ b/test/fixtures/with-config/layouts/custom.vue @@ -0,0 +1,6 @@ + diff --git a/test/fixtures/with-config/layouts/default.vue b/test/fixtures/with-config/layouts/default.vue new file mode 100644 index 0000000000..4555ce65c4 --- /dev/null +++ b/test/fixtures/with-config/layouts/default.vue @@ -0,0 +1,6 @@ + diff --git a/test/fixtures/with-config/pages/about.vue b/test/fixtures/with-config/pages/about.vue index 93009e1b3e..39572c46f1 100644 --- a/test/fixtures/with-config/pages/about.vue +++ b/test/fixtures/with-config/pages/about.vue @@ -4,3 +4,9 @@ Home page + + diff --git a/test/with-config.test.js b/test/with-config.test.js index fa6cf141fc..51304ad44a 100644 --- a/test/with-config.test.js +++ b/test/with-config.test.js @@ -27,9 +27,17 @@ test('/', async t => { test('/test/ (router base)', async t => { const window = await nuxt.renderAndGetWindow(url('/test/')) const html = window.document.body.innerHTML + t.true(html.includes('

Default layout

')) t.true(html.includes('

I have custom configurations

')) }) +test('/test/about (custom layout)', async t => { + const window = await nuxt.renderAndGetWindow(url('/test/about')) + const html = window.document.body.innerHTML + t.true(html.includes('

Custom layout

')) + t.true(html.includes('

About page

')) +}) + test('/test/env', async t => { const window = await nuxt.renderAndGetWindow(url('/test/env')) const html = window.document.body.innerHTML