fix(vue-app): middleware not executing on double browser back navigation (#6775)

fixes #6716.
This commit is contained in:
Jason Poindexter 2020-03-13 14:26:35 -07:00 committed by GitHub
parent a7052b637b
commit 1f5d489850
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -825,8 +825,8 @@ function addHotReload ($component, depth) {
router.beforeEach(loadAsyncComponents.bind(_app)) router.beforeEach(loadAsyncComponents.bind(_app))
router.beforeEach(render.bind(_app)) router.beforeEach(render.bind(_app))
// If page already is server rendered // If page already is server rendered and it was done on the same route path as client side render
if (NUXT.serverRendered) { if (NUXT.serverRendered && NUXT.routePath === _app.context.route.path) {
mount() mount()
return return
} }

View File

@ -72,10 +72,12 @@ export default async (ssrContext) => {
// Used for beforeNuxtRender({ Components, nuxtState }) // Used for beforeNuxtRender({ Components, nuxtState })
ssrContext.beforeRenderFns = [] ssrContext.beforeRenderFns = []
// Nuxt object (window{{globals.context}}, defaults to window.__NUXT__) // Nuxt object (window{{globals.context}}, defaults to window.__NUXT__)
ssrContext.nuxt = { <% if (features.layouts) { %>layout: 'default', <% } %>data: [], <% if (features.fetch) { %>fetch: [], <% } %>error: null<%= (store ? ', state: null' : '') %>, serverRendered: true } ssrContext.nuxt = { <% if (features.layouts) { %>layout: 'default', <% } %>data: [], <% if (features.fetch) { %>fetch: [], <% } %>error: null<%= (store ? ', state: null' : '') %>, serverRendered: true, routePath: '' }
// Create the app definition and the instance (created for each request) // Create the app definition and the instance (created for each request)
const { app, router<%= (store ? ', store' : '') %> } = await createApp(ssrContext) const { app, router<%= (store ? ', store' : '') %> } = await createApp(ssrContext)
const _app = new Vue(app) const _app = new Vue(app)
// Add ssr route path to nuxt context so we can account for page navigation between ssr and csr
ssrContext.nuxt.routePath = app.context.route.path
<% if (features.meta) { %> <% if (features.meta) { %>
// Add meta infos (used in renderer.js) // Add meta infos (used in renderer.js)