refacotr: replace ctx.error with _redirected

This commit is contained in:
Clark Du 2017-11-09 22:27:10 +08:00
parent 8868276e37
commit 37c256ade2
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9
3 changed files with 6 additions and 2 deletions

View File

@ -7,6 +7,9 @@ export default {
name: 'nuxt',
props: ['nuxtChildKey'],
render(h) {
if (this.nuxt._redirected) {
return h('div', [ 'redirecting.' ])
}
// If there is some error
if (this.nuxt.err) {
return h('nuxt-error', {

View File

@ -148,7 +148,8 @@ export async function setContext(app, context) {
}
if (process.server) {
app.context.res.setHeader('Location', path)
app.context.error({ statusCode: status, message: 'Redirecting to ' + path })
app.context.res.statusCode = status
app.nuxt._redirected = true
}
if (process.client) {
window.location = path

View File

@ -121,7 +121,7 @@ test('/redirect -> external link', async t => {
}
})
t.is(headers.Location, 'https://nuxtjs.org/')
t.true(html.includes('Redirecting to https://nuxtjs.org/'))
t.true(html.includes('<div>redirecting.</div>'))
})
test('/special-state -> check window.__NUXT__.test = true', async t => {