diff --git a/lib/app/client.js b/lib/app/client.js index c00c7dc749..1f171f4c1f 100644 --- a/lib/app/client.js +++ b/lib/app/client.js @@ -3,7 +3,7 @@ import Vue from 'vue' import middleware from './middleware' 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 noopFetch = () => {} let _lastPaths = [] @@ -26,20 +26,16 @@ function loadAsyncComponents (to, from, next) { if (typeof Component === 'function' && !Component.options) { return new Promise(function (resolve, reject) { const _resolve = (Component) => { - if (!Component.options) { - Component = Vue.extend(Component) // fix issue #6 - Component._Ctor = Component - } else { - Component._Ctor = Component - Component.extendOptions = Component.options - } + Component = sanitizeComponent(Component) match.components[key] = Component resolve(Component) } 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 toPath = to.fullPath.split('#')[0] @@ -328,13 +324,7 @@ const resolveComponents = flatMapComponents(router.match(path), (Component, _, m if (typeof Component === 'function' && !Component.options) { return new Promise(function (resolve, reject) { const _resolve = (Component) => { - if (!Component.options) { - Component = Vue.extend(Component) // fix issue #6 - Component._Ctor = Component - } else { - Component._Ctor = Component - Component.extendOptions = Component.options - } + Component = sanitizeComponent(Component) if (NUXT.serverRendered) { applyAsyncData(Component, NUXT.data[index]) } @@ -344,6 +334,8 @@ const resolveComponents = flatMapComponents(router.match(path), (Component, _, m Component().then(_resolve).catch(reject) }) } + Component = sanitizeComponent(Component) + match.components[key] = Component return Component }) diff --git a/lib/app/server.js b/lib/app/server.js index 4ccccf26eb..a53382293c 100644 --- a/lib/app/server.js +++ b/lib/app/server.js @@ -50,6 +50,7 @@ export default async (context) => { let Components = [] let promises = getMatchedComponents(router.match(context.url)).map((Component) => { return new Promise((resolve, reject) => { + if (typeof Component !== 'function') return resolve(sanitizeComponent(Component)) const _resolve = (Component) => resolve(sanitizeComponent(Component)) Component().then(_resolve).catch(reject) })