Skip to content

Commit d9a4626

Browse files
LinusBorgfnlctrl
authored andcommitted
Allows alias option to be an empty string. (#806)
1 parent e255599 commit d9a4626

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

examples/route-alias/app.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const Home = { template: '<div><h1>Home</h1><router-view></router-view></div>' }
77
const Foo = { template: '<div>foo</div>' }
88
const Bar = { template: '<div>bar</div>' }
99
const Baz = { template: '<div>baz</div>' }
10+
const Default = { template: '<div>default</div>' }
1011

1112
const router = new VueRouter({
1213
mode: 'history',
@@ -19,7 +20,9 @@ const router = new VueRouter({
1920
// relative alias (alias to /home/bar-alias)
2021
{ path: 'bar', component: Bar, alias: 'bar-alias' },
2122
// multiple aliases
22-
{ path: 'baz', component: Baz, alias: ['/baz', 'baz-alias'] }
23+
{ path: 'baz', component: Baz, alias: ['/baz', 'baz-alias'] },
24+
// default child route with empty string as alias.
25+
{ path: 'default', component: Default, alias: '' }
2326
]
2427
}
2528
]
@@ -46,6 +49,10 @@ new Vue({
4649
<li><router-link to="/home/baz-alias">
4750
/home/baz-alias (renders /home/baz)
4851
</router-link></li>
52+
53+
<li><router-link to="/home">
54+
/home (renders /home/default)
55+
</router-link></li>
4956
</ul>
5057
<router-view class="view"></router-view>
5158
</div>

src/create-route-map.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function addRouteRecord (
5959
})
6060
}
6161

62-
if (route.alias) {
62+
if (route.alias !== undefined) {
6363
if (Array.isArray(route.alias)) {
6464
route.alias.forEach(alias => {
6565
addRouteRecord(pathMap, nameMap, { path: alias }, parent, record.path)

test/e2e/specs/route-alias.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ module.exports = {
33
browser
44
.url('http://localhost:8080/route-alias/')
55
.waitForElementVisible('#app', 1000)
6-
.assert.count('li a', 4)
6+
.assert.count('li a', 5)
77
// assert correct href with base
88
.assert.attributeContains('li:nth-child(1) a', 'href', '/route-alias/foo')
99
.assert.attributeContains('li:nth-child(2) a', 'href', '/route-alias/home/bar-alias')
1010
.assert.attributeContains('li:nth-child(3) a', 'href', '/route-alias/baz')
1111
.assert.attributeContains('li:nth-child(4) a', 'href', '/route-alias/home/baz-alias')
12+
.assert.attributeEquals('li:nth-child(5) a', 'href', 'http://localhost:8080/route-alias/home')
1213

1314
.click('li:nth-child(1) a')
1415
.assert.urlEquals('http://localhost:8080/route-alias/foo')
@@ -29,6 +30,10 @@ module.exports = {
2930
.assert.urlEquals('http://localhost:8080/route-alias/home/baz-alias')
3031
.assert.containsText('.view', 'Home')
3132
.assert.containsText('.view', 'baz')
33+
.click('li:nth-child(5) a')
34+
.assert.urlEquals('http://localhost:8080/route-alias/home')
35+
.assert.containsText('.view', 'Home')
36+
.assert.containsText('.view', 'default')
3237

3338
// check initial visit
3439
.url('http://localhost:8080/route-alias/foo')
@@ -54,6 +59,12 @@ module.exports = {
5459
.assert.urlEquals('http://localhost:8080/route-alias/home/baz-alias')
5560
.assert.containsText('.view', 'Home')
5661
.assert.containsText('.view', 'baz')
62+
63+
.url('http://localhost:8080/route-alias/home')
64+
.waitForElementVisible('#app', 1000)
65+
.assert.urlEquals('http://localhost:8080/route-alias/home')
66+
.assert.containsText('.view', 'Home')
67+
.assert.containsText('.view', 'default')
5768
.end()
5869
}
5970
}

0 commit comments

Comments
 (0)