mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
fix(vue-app): static payload fetching bugfixes (#8701)
This commit is contained in:
parent
dc551f9709
commit
febd7ee43c
@ -324,22 +324,22 @@ export default {
|
||||
this._pagePayload = payload
|
||||
this._fetchCounters = {}
|
||||
},
|
||||
async fetchPayload(route) {
|
||||
async fetchPayload(route, prefetch) {
|
||||
<% if (nuxtOptions.generate.manifest) { %>
|
||||
const manifest = await this.fetchStaticManifest()
|
||||
const path = this.getRoutePath(route)
|
||||
if (!manifest.routes.includes(path)) {
|
||||
this.setPagePayload(false)
|
||||
if (!prefetch) { this.setPagePayload(false) }
|
||||
throw new Error(`Route ${path} is not pre-rendered`)
|
||||
}
|
||||
<% } %>
|
||||
const src = urlJoin(this.getStaticAssetsPath(route), 'payload.js')
|
||||
try {
|
||||
const payload = await window.__NUXT_IMPORT__(decodeURI(route), encodeURI(src))
|
||||
this.setPagePayload(payload)
|
||||
if (!prefetch) { this.setPagePayload(payload) }
|
||||
return payload
|
||||
} catch (err) {
|
||||
this.setPagePayload(false)
|
||||
if (!prefetch) { this.setPagePayload(false) }
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,9 @@ import {
|
||||
import { createApp<% if (features.layouts) { %>, NuxtError<% } %> } from './index.js'
|
||||
<% if (features.fetch) { %>import fetchMixin from './mixins/fetch.client'<% } %>
|
||||
import NuxtLink from './components/nuxt-link.<%= features.clientPrefetch ? "client" : "server" %>.js' // should be included after ./index.js
|
||||
<% if (isFullStatic) { %>import './jsonp'<% } %>
|
||||
<% if (isFullStatic) { %>import { installJsonp } from './jsonp'<% } %>
|
||||
|
||||
<% if (isFullStatic) { %>installJsonp()<% } %>
|
||||
|
||||
<% if (features.fetch) { %>
|
||||
// Fetch mixin
|
||||
|
@ -112,7 +112,7 @@ export default {
|
||||
if (!this.$root.isPreview) {
|
||||
const { href } = this.$router.resolve(this.to, this.$route, this.append)
|
||||
if (this.<%= globals.nuxt %>)
|
||||
this.<%= globals.nuxt %>.fetchPayload(href).catch(() => {})
|
||||
this.<%= globals.nuxt %>.fetchPayload(href, true).catch(() => {})
|
||||
}
|
||||
<% } %>
|
||||
<% if (router.linkPrefetchedClass) { %>
|
||||
|
@ -75,6 +75,9 @@ function importChunk(chunkId, src) {
|
||||
return promise
|
||||
}
|
||||
|
||||
export function installJsonp() {
|
||||
window.__NUXT_JSONP__ = function (chunkId, exports) { chunks[chunkId] = exports }
|
||||
window.__NUXT_JSONP_CACHE__ = chunks
|
||||
window.__NUXT_IMPORT__ = importChunk
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user