Skip to content

Commit d82eec8

Browse files
committed
only show loading bar when there are matching asyncData hooks
1 parent 980ca32 commit d82eec8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/entry-client.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ router.onReady(() => {
4444
const activated = matched.filter((c, i) => {
4545
return diffed || (diffed = (prevMatched[i] !== c))
4646
})
47-
if (!activated.length) {
47+
const asyncDataHooks = activated.map(c => c.asyncData).filter(_ => _)
48+
if (!asyncDataHooks.length) {
4849
return next()
4950
}
51+
5052
bar.start()
51-
Promise.all(activated.map(c => {
52-
if (c.asyncData) {
53-
return c.asyncData({ store, route: to })
54-
}
55-
})).then(() => {
56-
bar.finish()
57-
next()
58-
}).catch(next)
53+
Promise.all(asyncDataHooks.map(hook => hook({ store, route: to })))
54+
.then(() => {
55+
bar.finish()
56+
next()
57+
})
58+
.catch(next)
5959
})
6060

6161
// actually mount to DOM

0 commit comments

Comments
 (0)