fix(vue-app): add prefetched class to <nuxt-link> after chunk loaded (#6623)

This commit is contained in:
Sébastien Chopin 2019-10-28 15:32:24 +01:00 committed by Pooya Parsa
parent e3054314a9
commit 9f921fe136

View File

@ -92,15 +92,18 @@ export default {
// Stop observing this link (in case of internet connection changes)
observer.unobserve(this.$el)
const Components = this.getPrefetchComponents()
<% if (router.linkPrefetchedClass) { %>const promises = []<% } %>
for (const Component of Components) {
const componentOrPromise = Component()
if (componentOrPromise instanceof Promise) {
componentOrPromise.catch(() => {})
<% if (router.linkPrefetchedClass) { %>promises.push(componentOrPromise)<% } %>
}
Component.__prefetched = true
}<% if (router.linkPrefetchedClass) { %>
this.addPrefetchedClass()<% } %>
return Promise.all(promises).then(() => this.addPrefetchedClass())
<% } %>
}<% if (router.linkPrefetchedClass) { %>,
addPrefetchedClass () {
if (this.prefetchedClass !== 'false') {