fix(vue-app): prevent router.registerModule reallocation (#7915) (#7916)

This commit is contained in:
Jonas Galvez 2020-08-15 17:29:17 -03:00 committed by GitHub
parent 44471ec9df
commit fe0498cecd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import Vue from 'vue'
<% if (store) { %>import Vuex from 'vuex'<% } %>
<% if (features.meta) { %>import Meta from 'vue-meta'<% } %>
<% if (features.componentClientOnly) { %>import ClientOnly from 'vue-client-only'<% } %>
<% if (features.deprecations) { %>import NoSsr from 'vue-no-ssr'<% } %>
@ -66,6 +67,15 @@ const defaultTransition = <%=
%><%= isTest ? '// eslint-disable-line' : '' %>
<% } %>
<% if (store) { %>
const originalRegisterModule = Vuex.Store.prototype.registerModule
const baseStoreOptions = { preserveState: process.client }
function registerModule (path, rawModule, options = {}) {
return originalRegisterModule.call(this, path, rawModule, { ...baseStoreOptions, ...options })
}
<% } %>
async function createApp(ssrContext, config = {}) {
const router = await createRouter(ssrContext)
@ -75,8 +85,7 @@ async function createApp(ssrContext, config = {}) {
store.$router = router
<% if (mode === 'universal') { %>
// Fix SSR caveat https://github.com/nuxt/nuxt.js/issues/3757#issuecomment-414689141
const registerModule = store.registerModule
store.registerModule = (path, rawModule, options) => registerModule.call(store, path, rawModule, Object.assign({ preserveState: process.client }, options))
store.registerModule = registerModule
<% } %>
<% } %>