Merge pull request #2269 from clarkdo/external_url

fix: redirect relative path issue and message refactoring
This commit is contained in:
Sébastien Chopin 2017-11-28 15:32:01 +01:00 committed by GitHub
commit e2c0b17fb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 4 deletions

View File

@ -8,7 +8,7 @@ export default {
props: ['nuxtChildKey'], props: ['nuxtChildKey'],
render(h) { render(h) {
if (this.nuxt._redirected) { if (this.nuxt._redirected) {
return h('div', [ 'redirecting.' ]) return h('div', [ '<%= messages.redirect %>' ])
} }
// If there is some error // If there is some error
if (this.nuxt.err) { if (this.nuxt.err) {

View File

@ -132,7 +132,8 @@ export async function setContext(app, context) {
path = status path = status
status = 302 status = 302
} }
if (path.charAt(0) === '/' && path.charAt(1) !== '/') { // "/absolute/route", "./relative/route" or "../relative/route"
if (/(^[.]{1,2}\/)|(^\/(?!\/))/.test(path)) {
app.context.next({ app.context.next({
path: path, path: path,
query: query, query: query,

View File

@ -323,6 +323,7 @@ Options.defaults = {
back_to_home: 'Back to the home page', back_to_home: 'Back to the home page',
server_error_details: 'An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.', server_error_details: 'An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.',
client_error: 'Error', client_error: 'Error',
client_error_details: 'An error occurred while rendering the page. Check developer tools console for details.' client_error_details: 'An error occurred while rendering the page. Check developer tools console for details.',
redirect: 'Redirecting to external page.'
} }
} }

View File

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