mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
Fix context route in plugins for client-side
This commit is contained in:
parent
8f111a4d5e
commit
1b2b9dbbe7
@ -7,7 +7,7 @@ import NuxtLink from './components/nuxt-link.js'
|
|||||||
import NuxtError from '<%= components.ErrorPage ? components.ErrorPage : "./components/nuxt-error.vue" %>'
|
import NuxtError from '<%= components.ErrorPage ? components.ErrorPage : "./components/nuxt-error.vue" %>'
|
||||||
import Nuxt from './components/nuxt.vue'
|
import Nuxt from './components/nuxt.vue'
|
||||||
import App from '<%= appPath %>'
|
import App from '<%= appPath %>'
|
||||||
import { getContext } from './utils'
|
import { getContext, getLocation } from './utils'
|
||||||
<% if (store) { %>import { createStore } from './store.js'<% } %>
|
<% if (store) { %>import { createStore } from './store.js'<% } %>
|
||||||
<% plugins.forEach(plugin => { %>import <%= plugin.name %> from '<%= plugin.name %>'
|
<% plugins.forEach(plugin => { %>import <%= plugin.name %> from '<%= plugin.name %>'
|
||||||
<% }) %>
|
<% }) %>
|
||||||
@ -61,7 +61,7 @@ async function createApp (ssrContext) {
|
|||||||
// making them available everywhere as `this.$router` and `this.$store`.
|
// making them available everywhere as `this.$router` and `this.$store`.
|
||||||
const app = {
|
const app = {
|
||||||
router,
|
router,
|
||||||
<% if(store) { %> store,<% } %>
|
<% if(store) { %> store,<% } %>
|
||||||
_nuxt: {
|
_nuxt: {
|
||||||
defaultTransition,
|
defaultTransition,
|
||||||
transitions: [ defaultTransition ],
|
transitions: [ defaultTransition ],
|
||||||
@ -99,14 +99,18 @@ async function createApp (ssrContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const next = ssrContext ? ssrContext.next : location => app.router.push(location)
|
const next = ssrContext ? ssrContext.next : location => app.router.push(location)
|
||||||
|
let route = router.currentRoute
|
||||||
|
if (!ssrContext) {
|
||||||
|
const path = getLocation(router.options.base)
|
||||||
|
route = router.resolve(path).route
|
||||||
|
}
|
||||||
const ctx = getContext({
|
const ctx = getContext({
|
||||||
isServer: !!ssrContext,
|
isServer: !!ssrContext,
|
||||||
isClient: !ssrContext,
|
isClient: !ssrContext,
|
||||||
route: router.currentRoute,
|
route,
|
||||||
next,
|
next,
|
||||||
error: app._nuxt.error.bind(app),
|
error: app._nuxt.error.bind(app),
|
||||||
<% if(store) { %>store,<% } %>
|
<% if(store) { %>store,<% } %>
|
||||||
req: ssrContext ? ssrContext.req : undefined,
|
req: ssrContext ? ssrContext.req : undefined,
|
||||||
res: ssrContext ? ssrContext.res : undefined,
|
res: ssrContext ? ssrContext.res : undefined,
|
||||||
}, app)
|
}, app)
|
||||||
@ -121,8 +125,8 @@ async function createApp (ssrContext) {
|
|||||||
return {
|
return {
|
||||||
app,
|
app,
|
||||||
router,
|
router,
|
||||||
<% if(store) { %> store <% } %>
|
<% if(store) { %> store <% } %>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { createApp, NuxtError }
|
export { createApp, NuxtError }
|
||||||
|
Loading…
Reference in New Issue
Block a user