diff --git a/src/create-route-map.js b/src/create-route-map.js index 560e05fdd..826a8125f 100644 --- a/src/create-route-map.js +++ b/src/create-route-map.js @@ -112,32 +112,39 @@ function addRouteRecord ( }) } - if (route.alias !== undefined) { - const aliases = Array.isArray(route.alias) - ? route.alias - : [route.alias] - - aliases.forEach(alias => { - const aliasRoute = { - path: alias, - children: route.children - } - addRouteRecord( - pathList, - pathMap, - nameMap, - aliasRoute, - parent, - record.path || '/' // matchAs - ) - }) - } - if (!pathMap[record.path]) { pathList.push(record.path) pathMap[record.path] = record } + if (route.alias !== undefined) { + if (route.alias !== path) { + const aliases = Array.isArray(route.alias) + ? route.alias + : [route.alias] + + aliases.forEach(alias => { + const aliasRoute = { + path: alias, + children: route.children + } + addRouteRecord( + pathList, + pathMap, + nameMap, + aliasRoute, + parent, + record.path || '/' // matchAs + ) + }) + } else if (process.env.NODE_ENV !== 'production') { + warn( + false, + `Path with the same value as an alias: "${path}"` + ) + } + } + if (name) { if (!nameMap[name]) { nameMap[name] = record diff --git a/test/unit/specs/create-map.spec.js b/test/unit/specs/create-map.spec.js index 67fba131a..d0d451866 100644 --- a/test/unit/specs/create-map.spec.js +++ b/test/unit/specs/create-map.spec.js @@ -97,6 +97,18 @@ describe('Creating Route Map', function () { expect(console.warn.calls.argsFor(0)[0]).toMatch('vue-router] Duplicate param keys in route with path: "/foo/:id/bar/:id"') }) + it('in development, warn path with the same value as an alias', () => { + process.env.NODE_ENV = 'development' + maps = createRouteMap([ + { + path: '/foo-alias', component: Foo, + alias: '/foo-alias' + } + ]) + expect(console.warn).toHaveBeenCalled() + expect(console.warn.calls.argsFor(0)[0]).toMatch('vue-router] Path with the same value as an alias: "/foo-alias"') + }) + describe('path-to-regexp options', function () { const routes = [ { path: '/foo', name: 'foo', component: Foo },