fix(spa): redundant laoding default layout when custom layout specified

This commit is contained in:
Clark Du 2017-11-14 16:53:01 +08:00
parent 47384305da
commit fafe6d0a81
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9
2 changed files with 10 additions and 2 deletions

View File

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

View File

@ -8,8 +8,9 @@ const url = (route) => 'http://localhost:' + port + route
const renderRoute = async _url => {
const window = await nuxt.renderAndGetWindow(url(_url))
const head = window.document.head.innerHTML
const html = window.document.body.innerHTML
return { window, html }
return { window, head, html }
}
// 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'))
})
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
test.after('Closing server and nuxt.js', t => {
nuxt.close()