mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-06 06:41:09 +00:00
refactor(router): reduce duplicate code in routes.js (#4121)
This commit is contained in:
parent
411e89e52c
commit
a359424741
@ -1,5 +1,6 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Router from 'vue-router'
|
import Router from 'vue-router'
|
||||||
|
import { interopDefault } from './utils';
|
||||||
|
|
||||||
<% function recursiveRoutes(routes, tab, components) {
|
<% function recursiveRoutes(routes, tab, components) {
|
||||||
let res = ''
|
let res = ''
|
||||||
@ -32,7 +33,7 @@ const _routes = recursiveRoutes(router.routes, '\t\t', _components)
|
|||||||
const name = route._name
|
const name = route._name
|
||||||
|
|
||||||
if (splitChunks.pages) {
|
if (splitChunks.pages) {
|
||||||
return `const ${name} = () => import('${path}' /* webpackChunkName: "${chunkName}" */).then(m => m.default || m)`
|
return `const ${name} = () => interopDefault(import('${path}' /* webpackChunkName: "${chunkName}" */))`
|
||||||
} else {
|
} else {
|
||||||
return `import ${name} from '${path}'`
|
return `import ${name} from '${path}'`
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,10 @@ export function globalHandleError(error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function interopDefault(promise) {
|
||||||
|
return promise.then(m => m.default || m);
|
||||||
|
}
|
||||||
|
|
||||||
export function applyAsyncData(Component, asyncData) {
|
export function applyAsyncData(Component, asyncData) {
|
||||||
const ComponentData = Component.options.data || noopData
|
const ComponentData = Component.options.data || noopData
|
||||||
// Prevent calling this method for each request on SSR context
|
// Prevent calling this method for each request on SSR context
|
||||||
|
Loading…
Reference in New Issue
Block a user