mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 22:25:12 +00:00
Merge pull request #2105 from clarkdo/spa_layout
fix(spa): redundant laoding default layout when custom layout specified
This commit is contained in:
commit
ab56a29ee6
@ -528,10 +528,12 @@ async function mountApp(__app) {
|
|||||||
// Create Vue instance
|
// Create Vue instance
|
||||||
const _app = new Vue(app)
|
const _app = new Vue(app)
|
||||||
|
|
||||||
// Load layout
|
<% if (mode !== 'spa') { %>
|
||||||
|
// 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 = () => {
|
||||||
|
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user