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
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user