diff --git a/lib/app/router.js b/lib/app/router.js index 2238ee8ef3..b49a436aa9 100644 --- a/lib/app/router.js +++ b/lib/app/router.js @@ -7,8 +7,9 @@ import Router from 'vue-router' route._name = '_' + hash(route.component) components.push({ _name: route._name, component: route.component, name: route.name, chunkName: route.chunkName }) res += tab + '{\n' - res += tab + '\tpath: ' + JSON.stringify(route.path) + ',\n' - res += tab + '\tcomponent: ' + (splitPages ? route._name : `() => ${route._name}.default || ${route._name}`) + res += tab + '\tpath: ' + JSON.stringify(route.path) + res += (route.component) ? ',\n\t' + tab + 'component: ' + (splitPages ? route._name : `() => ${route._name}.default || ${route._name}`) : '' + res += (route.redirect) ? ',\n\t' + tab + 'redirect: ' + JSON.stringify(route.redirect) : '' res += (route.name) ? ',\n\t' + tab + 'name: ' + JSON.stringify(route.name) : '' res += (route.children) ? ',\n\t' + tab + 'children: [\n' + recursiveRoutes(routes[i].children, tab + '\t\t', components) + '\n\t' + tab + ']' : '' res += '\n' + tab + '}' + (i + 1 === routes.length ? '' : ',\n') @@ -18,6 +19,7 @@ import Router from 'vue-router' const _components = [] const _routes = recursiveRoutes(router.routes, '\t\t', _components) %><%= uniqBy(_components, '_name').map((route) => { + if (!route.component) return '' const path = relativeToBuild(route.component) const chunkName = wChunk(route.chunkName) const name = route._name diff --git a/test/fixtures/with-config/nuxt.config.js b/test/fixtures/with-config/nuxt.config.js index 1997fd52ad..9814f16634 100644 --- a/test/fixtures/with-config/nuxt.config.js +++ b/test/fixtures/with-config/nuxt.config.js @@ -12,6 +12,10 @@ module.exports = { name: 'about-bis', path: '/about-bis', component: '~/pages/about.vue' + }, + { + path: '/redirect/about-bis', + redirect: '/about-bis' } ] } diff --git a/test/with-config.test.js b/test/with-config.test.js index 8900379d10..0db4283f0c 100644 --- a/test/with-config.test.js +++ b/test/with-config.test.js @@ -171,6 +171,21 @@ test.serial('/test/about-bis (added with extendRoutes)', async t => { t.true(html.includes('