From 103a8158b72bb3a4329b1cc5c2a9375b65e748b9 Mon Sep 17 00:00:00 2001 From: Razvan Stoenescu Date: Thu, 29 Sep 2022 16:34:12 +0300 Subject: [PATCH] fix(app): (backport from Qv2's q/app-*) preFetch may error out with newer vue-router #14172 --- app/templates/entry/client-prefetch.js | 6 +++++- app/templates/entry/server-entry.js | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/templates/entry/client-prefetch.js b/app/templates/entry/client-prefetch.js index aaf053040a1..d31f5bc86e0 100644 --- a/app/templates/entry/client-prefetch.js +++ b/app/templates/entry/client-prefetch.js @@ -30,7 +30,11 @@ function getMatchedComponents (to, router) { if (!route) { return [] } - return Array.prototype.concat.apply([], route.matched.map(m => { + const matched = route.matched.filter(m => m.components !== void 0) + + if (matched.length === 0) { return [] } + + return Array.prototype.concat.apply([], matched.map(m => { return Object.keys(m.components).map(key => { const comp = m.components[key] return { diff --git a/app/templates/entry/server-entry.js b/app/templates/entry/server-entry.js index d52f4d81811..39cb86714d2 100644 --- a/app/templates/entry/server-entry.js +++ b/app/templates/entry/server-entry.js @@ -123,6 +123,7 @@ export default context => { // wait until router has resolved possible async hooks router.onReady(() => { const matchedComponents = router.getMatchedComponents() + .filter(m => m !== void 0) .map(m => m.options /* Vue.extend() */ || m) // no matched routes