fix: return 404 if extendRoutes without Component (#3608)

resolve #3351
This commit is contained in:
Clark Du 2018-08-13 17:27:20 +01:00 committed by GitHub
parent 09188dd173
commit 5ddc394a50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View File

@ -77,9 +77,14 @@ export function getMatchedComponentsInstances(route, matches = false) {
export function flatMapComponents(route, fn) {
return Array.prototype.concat.apply([], route.matched.map(function (m, index) {
return Object.keys(m.components).map(function (key) {
return fn(m.components[key], m.instances[key], m, key, index)
})
return Object.keys(m.components).reduce(function (promises, key) {
if (m.components[key]) {
promises.push(fn(m.components[key], m.instances[key], m, key, index))
} else {
delete m.components[key]
}
return promises
}, [])
}))
}

View File

@ -20,6 +20,9 @@ export default {
{
path: '/redirect/about-bis',
redirect: '/about-bis'
},
{
path: '/not-existed'
}
]
}

View File

@ -112,6 +112,11 @@ describe('with-config', () => {
expect(html.includes('<h1>About page</h1>')).toBe(true)
})
test('/test/not-existed should return 404', async () => {
await expect(rp(url('/test/not-existed')))
.rejects.toMatchObject({ statusCode: 404 })
})
test('/test/redirect/about-bis (redirect with extendRoutes)', async () => {
const window = await nuxt.renderAndGetWindow(url('/test/redirect/about-bis'))
const windowHref = window.location.href