mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
Add redirect in plugins context
This commit is contained in:
parent
c25aa4bc45
commit
5e5b58c461
@ -111,15 +111,16 @@ async function createApp (ssrContext) {
|
|||||||
...App
|
...App
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const next = ssrContext ? ssrContext.next : (location) => app.router.push(location)
|
||||||
const ctx = getContext({
|
const ctx = getContext({
|
||||||
isServer: !!ssrContext,
|
isServer: !!ssrContext,
|
||||||
isClient: !ssrContext,
|
isClient: !ssrContext,
|
||||||
route: router.currentRoute,
|
route: router.currentRoute,
|
||||||
|
next,
|
||||||
<%= (store ? 'store,' : '') %>
|
<%= (store ? 'store,' : '') %>
|
||||||
req: ssrContext ? ssrContext.req : undefined,
|
req: ssrContext ? ssrContext.req : undefined,
|
||||||
res: ssrContext ? ssrContext.res : undefined,
|
res: ssrContext ? ssrContext.res : undefined,
|
||||||
}, app)
|
}, app)
|
||||||
delete ctx.redirect
|
|
||||||
delete ctx.error
|
delete ctx.error
|
||||||
|
|
||||||
// Inject external plugins
|
// Inject external plugins
|
||||||
|
@ -17,15 +17,6 @@ const isDev = <%= isDev %>
|
|||||||
// Since data fetching is async, this function is expected to
|
// Since data fetching is async, this function is expected to
|
||||||
// return a Promise that resolves to the app instance.
|
// return a Promise that resolves to the app instance.
|
||||||
export default async (context) => {
|
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
|
// create context.next for simulate next() of beforeEach() when wanted to redirect
|
||||||
context.redirected = false
|
context.redirected = false
|
||||||
context.next = function (opts) {
|
context.next = function (opts) {
|
||||||
@ -45,6 +36,15 @@ export default async (context) => {
|
|||||||
})
|
})
|
||||||
context.res.end()
|
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
|
// Add meta infos
|
||||||
context.meta = _app.$meta()
|
context.meta = _app.$meta()
|
||||||
// Error function
|
// Error function
|
||||||
|
Loading…
Reference in New Issue
Block a user