diff --git a/src/create-route-map.js b/src/create-route-map.js index 560e05fdd..9dc572cf2 100644 --- a/src/create-route-map.js +++ b/src/create-route-map.js @@ -47,7 +47,8 @@ function addRouteRecord ( nameMap: Dictionary, route: RouteConfig, parent?: RouteRecord, - matchAs?: string + matchAs?: string, + isAnAlias?: boolean ) { const { path, name } = route if (process.env.NODE_ENV !== 'production') { @@ -57,6 +58,12 @@ function addRouteRecord ( `route config "component" for path: ${String(path || name)} cannot be a ` + `string id. Use an actual component instead.` ) + warn( + route.component || route.components || route.redirect || route.beforeEnter || isAnAlias, + `route config "component" for path: ${String(path || name)} should be either a ` + + `component (or named component), redirection, navigation guard, or an alias ` + + `to another root.` + ) } const pathToRegexpOptions: PathToRegexpOptions = route.pathToRegexpOptions || {} @@ -128,7 +135,8 @@ function addRouteRecord ( nameMap, aliasRoute, parent, - record.path || '/' // matchAs + record.path || '/', // matchAs + true ) }) } diff --git a/test/unit/specs/create-map.spec.js b/test/unit/specs/create-map.spec.js index 67fba131a..c838666ab 100644 --- a/test/unit/specs/create-map.spec.js +++ b/test/unit/specs/create-map.spec.js @@ -78,6 +78,12 @@ describe('Creating Route Map', function () { }).toThrowError(/"path" is required/) }) + it('in development, throws if component is null or undefined', function () { + process.env.NODE_ENV = 'development' + maps = createRouteMap([{ path: '/' }]) + expect(console.warn).toHaveBeenCalled() + }) + it('in production, it has not logged this warning', function () { maps = createRouteMap(routes) expect(console.warn).not.toHaveBeenCalled()