diff --git a/lib/app/utils.js b/lib/app/utils.js index 49ca3577c9..4f2d4a096e 100644 --- a/lib/app/utils.js +++ b/lib/app/utils.js @@ -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 + }, []) })) } diff --git a/test/fixtures/with-config/nuxt.config.js b/test/fixtures/with-config/nuxt.config.js index 54e22ee28a..31d2f9c413 100644 --- a/test/fixtures/with-config/nuxt.config.js +++ b/test/fixtures/with-config/nuxt.config.js @@ -20,6 +20,9 @@ export default { { path: '/redirect/about-bis', redirect: '/about-bis' + }, + { + path: '/not-existed' } ] } diff --git a/test/unit/with-config.test.js b/test/unit/with-config.test.js index 22bf6fe7db..9568fce82c 100644 --- a/test/unit/with-config.test.js +++ b/test/unit/with-config.test.js @@ -112,6 +112,11 @@ describe('with-config', () => { expect(html.includes('

About page

')).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