Skip to content

Commit

Permalink
fix: handle static option in page
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Jul 25, 2019
1 parent 6dca4d1 commit 8b1668f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions modules/static/plugin.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { getMatchedComponents } from './utils.js'
import Middleware from './middleware'

const hasStaticAsyncData = (Component) => Boolean(Component.options.asyncData) && Component.options.static !== false

Middleware.nuxt_static = async ({ app, route }) => {
// Ignore on server
if (process.server) return
Expand All @@ -10,12 +12,12 @@ Middleware.nuxt_static = async ({ app, route }) => {
const Components = getMatchedComponents(route)
Components.forEach(Component => {
Component._payloads = Component._payloads || {}
if (Component.options.asyncData) {
if (hasStaticAsyncData(Component)) {
Component.options.asyncData = ({ route }) => Component._payloads[route.path.replace(/\/$/, '')]
}
})
const path = route.path.replace(/\/$/, '')
const needFetch = Components.some(Component => Component.options.asyncData && !Component._payloads[path])
const needFetch = Components.some(Component => hasStaticAsyncData(Component) && !Component._payloads[path])
if (!needFetch) {
return
}
Expand All @@ -27,7 +29,7 @@ Middleware.nuxt_static = async ({ app, route }) => {
if (!pageDatas) return console.error(`[@nuxt/static] Could not fetch ${payloadPath}`)

Components.forEach((Component, index) => {
if (Component.options.asyncData) {
if (hasStaticAsyncData(Component)) {
Component._payloads[path] = pageDatas[index]
}
})
Expand Down

0 comments on commit 8b1668f

Please sign in to comment.