diff --git a/lib/app.js b/lib/app.js index d19e816..a89d42a 100644 --- a/lib/app.js +++ b/lib/app.js @@ -123,6 +123,11 @@ module.exports = (app, options) => { renderer.renderToString(context, (err, renderedHtml) => { let html = renderedHtml + if (context.httpCode !== res.statusCode) { + // If someone asked for a redirection through `this.$ssrContext.req.res.redirect(302, redirectUri)` for example, take it in account + context.httpCode = res.statusCode + } + if (err || context.httpCode === 500) { console.error(`error during render url : ${req.url}`) @@ -157,7 +162,10 @@ module.exports = (app, options) => { config.onRender(res, context) } - res.send(html) + // In case it's a redirection the body should be sent + if (res.statusCode !== 301 && res.statusCode !== 302) { + res.send(html) + } }) }