Add redirect in plugins context

This commit is contained in:
Sebastien Chopin 2017-06-06 14:51:49 +02:00
parent c25aa4bc45
commit 5e5b58c461
2 changed files with 11 additions and 10 deletions

View File

@ -111,15 +111,16 @@ async function createApp (ssrContext) {
...App
}
const next = ssrContext ? ssrContext.next : (location) => app.router.push(location)
const ctx = getContext({
isServer: !!ssrContext,
isClient: !ssrContext,
route: router.currentRoute,
next,
<%= (store ? 'store,' : '') %>
req: ssrContext ? ssrContext.req : undefined,
res: ssrContext ? ssrContext.res : undefined,
}, app)
delete ctx.redirect
delete ctx.error
// Inject external plugins

View File

@ -17,15 +17,6 @@ const isDev = <%= isDev %>
// Since data fetching is async, this function is expected to
// return a Promise that resolves to the app instance.
export default async (context) => {
const { app, router<%= (store ? ', store' : '') %> } = await createApp(context)
const _app = new Vue(app)
const _noopApp = new Vue({ render: (h) => h('div') })
// Add store to the context
<%= (store ? 'context.store = store' : '') %>
// Add route to the context
context.route = router.currentRoute
// Nuxt object
context.nuxt = { layout: 'default', data: [], error: null<%= (store ? ', state: null' : '') %>, serverRendered: true }
// create context.next for simulate next() of beforeEach() when wanted to redirect
context.redirected = false
context.next = function (opts) {
@ -45,6 +36,15 @@ export default async (context) => {
})
context.res.end()
}
const { app, router<%= (store ? ', store' : '') %> } = await createApp(context)
const _app = new Vue(app)
const _noopApp = new Vue({ render: (h) => h('div') })
// Add store to the context
<%= (store ? 'context.store = store' : '') %>
// Add route to the context
context.route = router.currentRoute
// Nuxt object
context.nuxt = { layout: 'default', data: [], error: null<%= (store ? ', state: null' : '') %>, serverRendered: true }
// Add meta infos
context.meta = _app.$meta()
// Error function