diff --git a/packages/vue-app/template/utils.js b/packages/vue-app/template/utils.js index fdd9f97bd8..f75edf392e 100644 --- a/packages/vue-app/template/utils.js +++ b/packages/vue-app/template/utils.js @@ -106,6 +106,9 @@ export function resolveRouteComponents(route) { } export async function getRouteData(route) { + if (!route) { + return + } // Make sure the components are resolved (code-splitting) await resolveRouteComponents(route) // Send back a copy of route with meta based on Component definition @@ -188,19 +191,27 @@ export async function setContext(app, context) { app.context.nuxtState = window.<%= globals.context %> } } + // Dynamic keys + const [currentRouteData, fromRouteData] = await Promise.all([ + getRouteData(context.route), + getRouteData(context.from) + ]) + + if (context.route) { + app.context.route = currentRouteData + } + + if (context.from) { + app.context.from = fromRouteData + } + app.context.next = context.next app.context._redirected = false app.context._errored = false app.context.isHMR = !!context.isHMR - if (context.route) { - app.context.route = await getRouteData(context.route) - } app.context.params = app.context.route.params || {} app.context.query = app.context.route.query || {} - if (context.from) { - app.context.from = await getRouteData(context.from) - } } export function middlewareSeries(promises, appContext) {