From c98847ca530219d063f781bfc17c743e4c2c7aca Mon Sep 17 00:00:00 2001 From: Thorsten Date: Wed, 19 Oct 2016 22:02:37 +0200 Subject: [PATCH] Allows alias option to be an empty string. --- examples/route-alias/app.js | 9 ++++++++- src/create-route-map.js | 2 +- test/e2e/specs/route-alias.js | 13 ++++++++++++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/examples/route-alias/app.js b/examples/route-alias/app.js index de4f0ac0e..9ab0fc176 100644 --- a/examples/route-alias/app.js +++ b/examples/route-alias/app.js @@ -7,6 +7,7 @@ const Home = { template: '

Home

' } const Foo = { template: '
foo
' } const Bar = { template: '
bar
' } const Baz = { template: '
baz
' } +const Default = { template: '
default
' } const router = new VueRouter({ mode: 'history', @@ -19,7 +20,9 @@ const router = new VueRouter({ // relative alias (alias to /home/bar-alias) { path: 'bar', component: Bar, alias: 'bar-alias' }, // multiple aliases - { path: 'baz', component: Baz, alias: ['/baz', 'baz-alias'] } + { path: 'baz', component: Baz, alias: ['/baz', 'baz-alias'] }, + // default child route with empty string as alias. + { path: 'default', component: Default, alias: '' } ] } ] @@ -46,6 +49,10 @@ new Vue({
  • /home/baz-alias (renders /home/baz)
  • + +
  • + /home (renders /home/default) +
  • diff --git a/src/create-route-map.js b/src/create-route-map.js index 3b1f4d65e..7911e0258 100644 --- a/src/create-route-map.js +++ b/src/create-route-map.js @@ -59,7 +59,7 @@ function addRouteRecord ( }) } - if (route.alias) { + if (route.alias !== undefined) { if (Array.isArray(route.alias)) { route.alias.forEach(alias => { addRouteRecord(pathMap, nameMap, { path: alias }, parent, record.path) diff --git a/test/e2e/specs/route-alias.js b/test/e2e/specs/route-alias.js index bb61eae61..24282b946 100644 --- a/test/e2e/specs/route-alias.js +++ b/test/e2e/specs/route-alias.js @@ -3,12 +3,13 @@ module.exports = { browser .url('http://localhost:8080/route-alias/') .waitForElementVisible('#app', 1000) - .assert.count('li a', 4) + .assert.count('li a', 5) // assert correct href with base .assert.attributeContains('li:nth-child(1) a', 'href', '/route-alias/foo') .assert.attributeContains('li:nth-child(2) a', 'href', '/route-alias/home/bar-alias') .assert.attributeContains('li:nth-child(3) a', 'href', '/route-alias/baz') .assert.attributeContains('li:nth-child(4) a', 'href', '/route-alias/home/baz-alias') + .assert.attributeEquals('li:nth-child(5) a', 'href', 'http://localhost:8080/route-alias/home') .click('li:nth-child(1) a') .assert.urlEquals('http://localhost:8080/route-alias/foo') @@ -29,6 +30,10 @@ module.exports = { .assert.urlEquals('http://localhost:8080/route-alias/home/baz-alias') .assert.containsText('.view', 'Home') .assert.containsText('.view', 'baz') + .click('li:nth-child(5) a') + .assert.urlEquals('http://localhost:8080/route-alias/home') + .assert.containsText('.view', 'Home') + .assert.containsText('.view', 'default') // check initial visit .url('http://localhost:8080/route-alias/foo') @@ -54,6 +59,12 @@ module.exports = { .assert.urlEquals('http://localhost:8080/route-alias/home/baz-alias') .assert.containsText('.view', 'Home') .assert.containsText('.view', 'baz') + + .url('http://localhost:8080/route-alias/home') + .waitForElementVisible('#app', 1000) + .assert.urlEquals('http://localhost:8080/route-alias/home') + .assert.containsText('.view', 'Home') + .assert.containsText('.view', 'default') .end() } }