diff --git a/packages/generator/src/generator.js b/packages/generator/src/generator.js index 11a0d234b2..340edf296e 100644 --- a/packages/generator/src/generator.js +++ b/packages/generator/src/generator.js @@ -343,7 +343,7 @@ export default class Generator { // Save Static Assets if (this.staticAssetsDir && renderContext.staticAssets) { for (const asset of renderContext.staticAssets) { - const assetPath = path.join(this.staticAssetsDir, asset.path) + const assetPath = path.join(this.staticAssetsDir, decodeURI(asset.path)) await fsExtra.ensureDir(path.dirname(assetPath)) await fsExtra.writeFile(assetPath, asset.src, 'utf-8') } diff --git a/packages/vue-app/template/App.js b/packages/vue-app/template/App.js index ac7d595a95..a6ecf415e7 100644 --- a/packages/vue-app/template/App.js +++ b/packages/vue-app/template/App.js @@ -1,5 +1,5 @@ import Vue from 'vue' -import { parsePath, withoutTrailingSlash } from 'ufo' +import { parsePath, withoutTrailingSlash, normalizeURL } from 'ufo' <% utilsImports = [ ...(features.asyncData || features.fetch) ? [ 'getMatchedComponentsInstances', @@ -317,7 +317,7 @@ export default { }, <% if (nuxtOptions.generate.manifest) { %> async fetchStaticManifest() { - return window.__NUXT_IMPORT__('manifest.js', encodeURI(urlJoin(this.getStaticAssetsPath(), 'manifest.js'))) + return window.__NUXT_IMPORT__('manifest.js', normalizeURL(urlJoin(this.getStaticAssetsPath(), 'manifest.js'))) }, <% } %> setPagePayload(payload) { @@ -328,14 +328,14 @@ export default { <% if (nuxtOptions.generate.manifest) { %> const manifest = await this.fetchStaticManifest() const path = this.getRoutePath(route) - if (!manifest.routes.includes(path)) { + if (!manifest.routes.includes(decodeURI(path))) { 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)) + const payload = await window.__NUXT_IMPORT__(decodeURI(route), normalizeURL(src)) if (!prefetch) { this.setPagePayload(payload) } return payload } catch (err) { diff --git a/test/dev/full-static.test.js b/test/dev/full-static.test.js index ac41142f34..18dc3bbb60 100644 --- a/test/dev/full-static.test.js +++ b/test/dev/full-static.test.js @@ -1,7 +1,8 @@ import http from 'http' -import { resolve } from 'path' +import { join, resolve } from 'path' import serveStatic from 'serve-static' import finalhandler from 'finalhandler' +import glob from 'glob' import { Builder, Generator, getPort, loadFixture, Nuxt, rp } from '../utils' let port @@ -43,7 +44,21 @@ describe('full-static', () => { const { body: html } = await rp(url('/payload')) expect(html).toContain('