diff --git a/lib/app/router.js b/lib/app/router.js index b85b030586..9b0dc9f29a 100644 --- a/lib/app/router.js +++ b/lib/app/router.js @@ -1,5 +1,6 @@ import Vue from 'vue' import Router from 'vue-router' +import { interopDefault } from './utils'; <% function recursiveRoutes(routes, tab, components) { let res = '' @@ -25,14 +26,14 @@ import Router from 'vue-router' } const _components = [] const _routes = recursiveRoutes(router.routes, '\t\t', _components) -%><%= uniqBy(_components, '_name').map((route) => { +%> <%= uniqBy(_components, '_name').map((route) => { if (!route.component) return '' const path = relativeToBuild(route.component) const chunkName = wChunk(route.chunkName) const name = route._name if (splitChunks.pages) { - return `const ${name} = () => import('${path}' /* webpackChunkName: "${chunkName}" */).then(m => m.default || m)` + return `const ${name} = () => interopDefault(import('${path}' /* webpackChunkName: "${chunkName}" */))` } else { return `import ${name} from '${path}'` } diff --git a/lib/app/utils.js b/lib/app/utils.js index ecc1c261cc..47d696d5ab 100644 --- a/lib/app/utils.js +++ b/lib/app/utils.js @@ -19,6 +19,10 @@ export function globalHandleError(error) { } } +export function interopDefault(promise) { + return promise.then(m => m.default || m); +} + export function applyAsyncData(Component, asyncData) { const ComponentData = Component.options.data || noopData // Prevent calling this method for each request on SSR context