Merge pull request #2105 from clarkdo/spa_layout

fix(spa): redundant laoding default layout when custom layout specified
This commit is contained in:
Sébastien Chopin 2017-11-14 10:04:03 +01:00 committed by GitHub
commit ab56a29ee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -528,10 +528,12 @@ async function mountApp(__app) {
// Create Vue instance // Create Vue instance
const _app = new Vue(app) const _app = new Vue(app)
<% if (mode !== 'spa') { %>
// Load layout // Load layout
const layout = NUXT.layout || 'default' const layout = NUXT.layout || 'default'
await _app.loadLayout(layout) await _app.loadLayout(layout)
_app.setLayout(layout) _app.setLayout(layout)
<% } %>
// Mounts Vue app to DOM element // Mounts Vue app to DOM element
const mount = () => { const mount = () => {

View File

@ -8,8 +8,9 @@ const url = (route) => 'http://localhost:' + port + route
const renderRoute = async _url => { const renderRoute = async _url => {
const window = await nuxt.renderAndGetWindow(url(_url)) const window = await nuxt.renderAndGetWindow(url(_url))
const head = window.document.head.innerHTML
const html = window.document.body.innerHTML const html = window.document.body.innerHTML
return { window, html } return { window, head, html }
} }
// Init nuxt.js and create server listening on localhost:4000 // Init nuxt.js and create server listening on localhost:4000
@ -29,6 +30,11 @@ test('/custom (custom layout)', async t => {
t.true(html.includes('Custom layout')) t.true(html.includes('Custom layout'))
}) })
test('/custom (not default layout)', async t => {
const { head } = await renderRoute('/custom')
t.false(head.includes('src="/_nuxt/layouts/default.'))
})
// Close server and ask nuxt to stop listening to file changes // Close server and ask nuxt to stop listening to file changes
test.after('Closing server and nuxt.js', t => { test.after('Closing server and nuxt.js', t => {
nuxt.close() nuxt.close()