diff --git a/packages/vue-app/template/client.js b/packages/vue-app/template/client.js index cddfe76153..2b67e2517d 100644 --- a/packages/vue-app/template/client.js +++ b/packages/vue-app/template/client.js @@ -140,15 +140,21 @@ async function loadAsyncComponents(to, from, next) { <% } %> try { - const Components = await resolveRouteComponents(to) + const Components = await resolveRouteComponents( + to, + (Component, instance) => ({ Component, instance }) + ) <% if (loading) { %> if (!this._pathChanged && this._queryChanged) { // Add a marker on each component that it needs to refresh or not - const startLoader = Components.some((Component) => { + const startLoader = Components.some(({Component, instance}) => { const watchQuery = Component.options.watchQuery - if (watchQuery === true) return true - if (Array.isArray(watchQuery)) { + if (watchQuery === true) { + return true + } else if (Array.isArray(watchQuery)) { return watchQuery.some(key => this._diffQuery[key]) + } else if (typeof watchQuery === 'function') { + return watchQuery.apply(instance, [to.query, from.query]) } return false }) diff --git a/packages/vue-app/template/utils.js b/packages/vue-app/template/utils.js index 536d863f26..bffa91f029 100644 --- a/packages/vue-app/template/utils.js +++ b/packages/vue-app/template/utils.js @@ -98,15 +98,15 @@ export function flatMapComponents(route, fn) { })) } -export function resolveRouteComponents(route) { +export function resolveRouteComponents(route, fn) { return Promise.all( - flatMapComponents(route, async (Component, _, match, key) => { + flatMapComponents(route, async (Component, instance, match, key) => { // If component is a function, resolve it if (typeof Component === 'function' && !Component.options) { Component = await Component() } - match.components[key] = sanitizeComponent(Component) - return match.components[key] + match.components[key] = Component = sanitizeComponent(Component) + return typeof fn === 'function' ? fn(Component, instance, match, key) : Component }) ) }