mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 23:32:38 +00:00
fix: return 404 if extendRoutes without Component (#3608)
resolve #3351
This commit is contained in:
parent
09188dd173
commit
5ddc394a50
@ -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
|
||||
}, [])
|
||||
}))
|
||||
}
|
||||
|
||||
|
3
test/fixtures/with-config/nuxt.config.js
vendored
3
test/fixtures/with-config/nuxt.config.js
vendored
@ -20,6 +20,9 @@ export default {
|
||||
{
|
||||
path: '/redirect/about-bis',
|
||||
redirect: '/about-bis'
|
||||
},
|
||||
{
|
||||
path: '/not-existed'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user