diff --git a/lib/app/utils.js b/lib/app/utils.js index 7a8d399152..db83060cb0 100644 --- a/lib/app/utils.js +++ b/lib/app/utils.js @@ -61,6 +61,7 @@ export function getContext (context, app) { app: app, <%= (store ? 'store: context.store,' : '') %> route: (context.to ? context.to : context.route), + routePayload : context.routePayload, error: context.error, base: '<%= router.base %>', env: <%= JSON.stringify(env) %> diff --git a/lib/generate.js b/lib/generate.js index f8053455ac..99aa717aee 100644 --- a/lib/generate.js +++ b/lib/generate.js @@ -78,26 +78,30 @@ export default async function () { process.exit(1) throw e // eslint-disable-line no-unreachable } - /* - ** Generate html files from routes - */ - generateRoutes.forEach((route) => { - if (this.routes.indexOf(route) < 0) { - this.routes.push(route) + } + function decorateWithPayloads (routes) { + let routeMap = _(routes).map((route) => { + return [route, {route, routePayload: {}}] + }).fromPairs().value() + generateRoutes.forEach(({route, routePayload}) => { + if (!routeMap[route]) { + routeMap[route] = {route, routePayload} } }) + return _.values(routeMap) } /* ** Generate only index.html for router.mode = 'hash' */ - let routes = (this.options.router.mode === 'hash') ? ['/'] : this.routes + let routes = (this.options.router.mode === 'hash') ? [{route: '/'}] : decorateWithPayloads(this.routes) + while (routes.length) { let n = 0 - await Promise.all(routes.splice(0, 500).map(async (route) => { + await Promise.all(routes.splice(0, 500).map(async ({route, routePayload}) => { await waitFor(n++ * this.options.generate.interval) let html try { - const res = await this.renderRoute(route, { _generate: true }) + const res = await this.renderRoute(route, { _generate: true, routePayload }) html = res.html if (res.error) { errors.push({ type: 'handled', route, error: res.error }) diff --git a/test/fixtures/basic/nuxt.config.js b/test/fixtures/basic/nuxt.config.js index d6ba223b68..1ba6f25737 100644 --- a/test/fixtures/basic/nuxt.config.js +++ b/test/fixtures/basic/nuxt.config.js @@ -1,9 +1,9 @@ module.exports = { generate: { routes: [ - '/users/1', - '/users/2', - '/users/3' + {route: '/users/1'}, + {route: '/users/2'}, + {route: '/users/3'} ], interval: 200 }