Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/create-route-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ function addRouteRecord (
nameMap: Dictionary<RouteRecord>,
route: RouteConfig,
parent?: RouteRecord,
matchAs?: string
matchAs?: string,
isAnAlias?: boolean
) {
const { path, name } = route
if (process.env.NODE_ENV !== 'production') {
Expand All @@ -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 || {}
Expand Down Expand Up @@ -128,7 +135,8 @@ function addRouteRecord (
nameMap,
aliasRoute,
parent,
record.path || '/' // matchAs
record.path || '/', // matchAs
true
)
})
}
Expand Down
6 changes: 6 additions & 0 deletions test/unit/specs/create-map.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Copy link

@vinibrsl vinibrsl Feb 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would create an spec similar to this one, but to test that this is not affecting production env, with not.toHaveBeenCalled 👍

it('in production, it has not logged this warning', function () {
maps = createRouteMap(routes)
expect(console.warn).not.toHaveBeenCalled()
Expand Down