fix: Handle synchronous route component

This commit is contained in:
Sebastien Chopin 2017-09-07 13:40:10 +02:00
parent 226a8701b4
commit 74bc12da51

View File

@ -26,7 +26,6 @@ let router
// Try to rehydrate SSR data from window // Try to rehydrate SSR data from window
const NUXT = window.__NUXT__ || {} const NUXT = window.__NUXT__ || {}
NUXT.components = window.__COMPONENTS__ || null
<% if (debug || mode === 'spa') { %> <% if (debug || mode === 'spa') { %>
// Setup global Vue error handler // Setup global Vue error handler
@ -132,6 +131,14 @@ async function loadAsyncComponents (to, from, next) {
} }
} }
function applySSRData(Component) {
if (NUXT.serverRendered) {
applyAsyncData(Component, NUXT.data[index])
Component._Ctor = Component
}
return Component
}
// Get matched components // Get matched components
function resolveComponents(router) { function resolveComponents(router) {
const path = getLocation(router.options.base, router.options.mode) const path = getLocation(router.options.base, router.options.mode)
@ -139,23 +146,16 @@ function resolveComponents(router) {
return flatMapComponents(router.match(path), (Component, _, match, key, index) => { return flatMapComponents(router.match(path), (Component, _, match, key, index) => {
// If component already resolved // If component already resolved
if (typeof Component !== 'function' || Component.options) { if (typeof Component !== 'function' || Component.options) {
const _Component = sanitizeComponent(Component) const _Component = applySSRData(sanitizeComponent(Component))
match.components[key] = _Component match.components[key] = _Component
return _Component return _Component
} }
// Resolve component // Resolve component
return Component().then(Component => { return Component().then(Component => {
const _Component = sanitizeComponent(Component) const _Component = applySSRData(sanitizeComponent(Component))
if (NUXT.serverRendered) { match.components[key] = _Component
applyAsyncData(_Component, NUXT.data[index]) return _Component
if (NUXT.components) {
Component.options.components = Object.assign(_Component.options.components, NUXT.components[index])
}
_Component._Ctor = _Component
}
match.components[key] = _Component
return _Component
}) })
}) })
} }