Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Silence default child warning when redirecting #1442

Merged
merged 2 commits into from
Jun 16, 2017
Merged
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
4 changes: 2 additions & 2 deletions src/create-route-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ function addRouteRecord (
}

if (route.children) {
// Warn if route is named and has a default child route.
// Warn if route is named, does not redirect and has a default child route.
// If users navigate to this route by name, the default child will
// not be rendered (GH Issue #629)
if (process.env.NODE_ENV !== 'production') {
if (route.name && route.children.some(child => /^\/?$/.test(child.path))) {
if (route.name && !route.redirect && route.children.some(child => /^\/?$/.test(child.path))) {
warn(
false,
`Named Route '${route.name}' has a default child route. ` +
Expand Down
17 changes: 15 additions & 2 deletions test/unit/specs/create-map.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ const routes = [
name: 'bar.baz'
}
]
},
{
path: '/bar-redirect',
name: 'bar-redirect',
redirect: { name: 'bar-redirect.baz' },
component: Bar,
children: [
{
path: '',
component: Baz,
name: 'bar-redirect.baz'
}
]
}
]

Expand All @@ -42,7 +55,7 @@ describe('Creating Route Map', function () {
})

it('has a pathList which places wildcards at the end', () => {
expect(maps.pathList).toEqual(['', '/foo', '/bar/', '/bar', '*'])
expect(maps.pathList).toEqual(['', '/foo', '/bar/', '/bar', '/bar-redirect/', '/bar-redirect', '*'])
})

it('has a nameMap object for default subroute at \'bar.baz\'', function () {
Expand All @@ -52,7 +65,7 @@ describe('Creating Route Map', function () {
it('in development, has logged a warning concerning named route of parent and default subroute', function () {
process.env.NODE_ENV = 'development'
maps = createRouteMap(routes)
expect(console.warn).toHaveBeenCalled()
expect(console.warn).toHaveBeenCalledTimes(1)
expect(console.warn.calls.argsFor(0)[0]).toMatch('vue-router] Named Route \'bar\'')
})

Expand Down