mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-24 06:35:10 +00:00
Should work with route not code-splitted
This commit is contained in:
parent
7146b0f2a8
commit
1f317a188b
@ -3,7 +3,7 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import middleware from './middleware'
|
import middleware from './middleware'
|
||||||
import { createApp, NuxtError } from './index'
|
import { createApp, NuxtError } from './index'
|
||||||
import { applyAsyncData, getMatchedComponents, getMatchedComponentsInstances, flatMapComponents, getContext, middlewareSeries, promisify, getLocation, compile } from './utils'
|
import { applyAsyncData, sanitizeComponent, getMatchedComponents, getMatchedComponentsInstances, flatMapComponents, getContext, middlewareSeries, promisify, getLocation, compile } from './utils'
|
||||||
const noopData = () => { return {} }
|
const noopData = () => { return {} }
|
||||||
const noopFetch = () => {}
|
const noopFetch = () => {}
|
||||||
let _lastPaths = []
|
let _lastPaths = []
|
||||||
@ -26,20 +26,16 @@ function loadAsyncComponents (to, from, next) {
|
|||||||
if (typeof Component === 'function' && !Component.options) {
|
if (typeof Component === 'function' && !Component.options) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
const _resolve = (Component) => {
|
const _resolve = (Component) => {
|
||||||
if (!Component.options) {
|
Component = sanitizeComponent(Component)
|
||||||
Component = Vue.extend(Component) // fix issue #6
|
|
||||||
Component._Ctor = Component
|
|
||||||
} else {
|
|
||||||
Component._Ctor = Component
|
|
||||||
Component.extendOptions = Component.options
|
|
||||||
}
|
|
||||||
match.components[key] = Component
|
match.components[key] = Component
|
||||||
resolve(Component)
|
resolve(Component)
|
||||||
}
|
}
|
||||||
Component().then(_resolve).catch(reject)
|
Component().then(_resolve).catch(reject)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return Component
|
Component = sanitizeComponent(Component)
|
||||||
|
match.components[key] = Component
|
||||||
|
return match.components[key]
|
||||||
})
|
})
|
||||||
const fromPath = from.fullPath.split('#')[0]
|
const fromPath = from.fullPath.split('#')[0]
|
||||||
const toPath = to.fullPath.split('#')[0]
|
const toPath = to.fullPath.split('#')[0]
|
||||||
@ -328,13 +324,7 @@ const resolveComponents = flatMapComponents(router.match(path), (Component, _, m
|
|||||||
if (typeof Component === 'function' && !Component.options) {
|
if (typeof Component === 'function' && !Component.options) {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
const _resolve = (Component) => {
|
const _resolve = (Component) => {
|
||||||
if (!Component.options) {
|
Component = sanitizeComponent(Component)
|
||||||
Component = Vue.extend(Component) // fix issue #6
|
|
||||||
Component._Ctor = Component
|
|
||||||
} else {
|
|
||||||
Component._Ctor = Component
|
|
||||||
Component.extendOptions = Component.options
|
|
||||||
}
|
|
||||||
if (NUXT.serverRendered) {
|
if (NUXT.serverRendered) {
|
||||||
applyAsyncData(Component, NUXT.data[index])
|
applyAsyncData(Component, NUXT.data[index])
|
||||||
}
|
}
|
||||||
@ -344,6 +334,8 @@ const resolveComponents = flatMapComponents(router.match(path), (Component, _, m
|
|||||||
Component().then(_resolve).catch(reject)
|
Component().then(_resolve).catch(reject)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Component = sanitizeComponent(Component)
|
||||||
|
match.components[key] = Component
|
||||||
return Component
|
return Component
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ export default async (context) => {
|
|||||||
let Components = []
|
let Components = []
|
||||||
let promises = getMatchedComponents(router.match(context.url)).map((Component) => {
|
let promises = getMatchedComponents(router.match(context.url)).map((Component) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
if (typeof Component !== 'function') return resolve(sanitizeComponent(Component))
|
||||||
const _resolve = (Component) => resolve(sanitizeComponent(Component))
|
const _resolve = (Component) => resolve(sanitizeComponent(Component))
|
||||||
Component().then(_resolve).catch(reject)
|
Component().then(_resolve).catch(reject)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user