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
17 changes: 17 additions & 0 deletions src/create-route-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ function addRouteRecord (
if (typeof route.caseSensitive === 'boolean') {
pathToRegexpOptions.sensitive = route.caseSensitive
}
// =============================================================

if (process.env.NODE_ENV !== 'production') {
if (
route.component === null ||
(route.components != null &&
Object.keys(route.components).some(
key => route.components != null && route.components[key] === null
))
) {
warn(
false,
`Route with path "${route.path}" has a null component.`
)
}
}
// ====================================================

const record: RouteRecord = {
path: normalizedPath,
Expand Down
14 changes: 14 additions & 0 deletions test/unit/specs/create-matcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ describe('Creating Matcher', function () {
)
})

it('in development, warns if a route component is null', function () {
process.env.NODE_ENV = 'development'

createMatcher([
{ path: '/null-test', component: null }
])

expect(console.warn).toHaveBeenCalled()
expect(console.warn.calls.argsFor(0)[0]).toMatch(
'Route with path "/null-test" has a null component'
)
})

it('in production, it has not logged this warning', function () {
match({ name: 'foo' }, routes[0])
expect(console.warn).not.toHaveBeenCalled()
Expand Down Expand Up @@ -152,3 +165,4 @@ describe('Creating Matcher', function () {
expect(pathForNotFoundRoute).toEqual('/')
})
})

Loading