From 20fb174f51fafa86086119087d9c82137d3c19ea Mon Sep 17 00:00:00 2001 From: Dean Codemo Date: Sat, 20 May 2017 19:51:30 +1000 Subject: [PATCH 1/2] Silence default child warning when redirecting There is no need to warn about a named route that has a default child route if the named route intentionally redirects. --- src/create-route-map.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/create-route-map.js b/src/create-route-map.js index c68d211b7..17bd3eb17 100644 --- a/src/create-route-map.js +++ b/src/create-route-map.js @@ -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. ` + From 05ba35c26b9136d29b9bd8d2cda1506e45aab8f1 Mon Sep 17 00:00:00 2001 From: Dean Codemo Date: Sat, 20 May 2017 20:23:59 +1000 Subject: [PATCH 2/2] Updates create-map spec for redirecting route --- test/unit/specs/create-map.spec.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/test/unit/specs/create-map.spec.js b/test/unit/specs/create-map.spec.js index ff1ccf46d..f77e0d392 100644 --- a/test/unit/specs/create-map.spec.js +++ b/test/unit/specs/create-map.spec.js @@ -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' + } + ] } ] @@ -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 () { @@ -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\'') })