feat: dynamic spa using serverMiddleware

This commit is contained in:
Pooya Parsa 2017-08-05 13:08:21 +04:30
parent 1f4dfa5f44
commit 8b63b64f54
1 changed files with 14 additions and 12 deletions

View File

@ -412,21 +412,23 @@ export default class Renderer extends Tapable {
context.url = url context.url = url
context.isServer = true context.isServer = true
// Basic response if SSR is disabled // Basic response if SSR is disabled or spa data provided
if (this.noSSR) { const SPAData = context.spa || (context.res && context.res.spa)
let APP = '<div id="__nuxt"></div>' if (this.noSSR || SPAData) {
let HEAD = '' const data = {
let html = this.resources.spaTemplate({
HTML_ATTRS: '', HTML_ATTRS: '',
BODY_ATTRS: '', BODY_ATTRS: '',
HEAD, HEAD: '',
APP APP: <div id="__nuxt"></div>
})
return {
html
} }
if (SPAData) {
Object.assign(data, SPAData)
}
const html = this.resources.spaTemplate(data)
return { html }
} }
// Call renderToString from the bundleRenderer and generate the HTML (will update the context as well) // Call renderToString from the bundleRenderer and generate the HTML (will update the context as well)