Skip to content

Commit eb53ee4

Browse files
committed
always expose route name (fix #595, close #591)
1 parent 0eac747 commit eb53ee4

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

examples/named-routes/app.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import VueRouter from 'vue-router'
33

44
Vue.use(VueRouter)
55

6-
const Home = { template: '<div>home</div>' }
7-
const Foo = { template: '<div>foo</div>' }
8-
const Bar = { template: '<div>bar</div>' }
6+
const Home = { template: '<div>This is Home</div>' }
7+
const Foo = { template: '<div>This is Foo</div>' }
8+
const Bar = { template: '<div>This is Bar</div>' }
99

1010
const router = new VueRouter({
1111
mode: 'history',
@@ -22,6 +22,7 @@ new Vue({
2222
template: `
2323
<div id="app">
2424
<h1>Named Routes</h1>
25+
<p>Current route name: {{ $route.name }}</p>
2526
<ul>
2627
<li><router-link :to="{ name: 'home' }">home</router-link></li>
2728
<li><router-link :to="{ name: 'foo' }">foo</router-link></li>

src/create-matcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export function createRoute (
125125
redirectedFrom?: Location
126126
): Route {
127127
const route: Route = {
128-
name: location.name,
128+
name: location.name || (record && record.name),
129129
path: location.path || '/',
130130
hash: location.hash || '',
131131
query: location.query || {},

test/e2e/specs/named-routes.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,29 @@ module.exports = {
88
.assert.attributeContains('li:nth-child(1) a', 'href', '/named-routes/')
99
.assert.attributeContains('li:nth-child(2) a', 'href', '/named-routes/foo')
1010
.assert.attributeContains('li:nth-child(3) a', 'href', '/named-routes/bar')
11-
.assert.containsText('.view', 'home')
11+
.assert.containsText('p', 'Current route name: home')
12+
.assert.containsText('.view', 'Home')
1213

1314
.click('li:nth-child(2) a')
1415
.assert.urlEquals('http://localhost:8080/named-routes/foo')
15-
.assert.containsText('.view', 'foo')
16+
.assert.containsText('p', 'Current route name: foo')
17+
.assert.containsText('.view', 'Foo')
1618

1719
.click('li:nth-child(3) a')
1820
.assert.urlEquals('http://localhost:8080/named-routes/bar')
19-
.assert.containsText('.view', 'bar')
21+
.assert.containsText('p', 'Current route name: bar')
22+
.assert.containsText('.view', 'Bar')
2023

2124
.click('li:nth-child(1) a')
2225
.assert.urlEquals('http://localhost:8080/named-routes/')
23-
.assert.containsText('.view', 'home')
26+
.assert.containsText('p', 'Current route name: home')
27+
.assert.containsText('.view', 'Home')
2428

2529
// check initial visit
2630
.url('http://localhost:8080/named-routes/foo')
2731
.waitForElementVisible('#app', 1000)
28-
.assert.containsText('.view', 'foo')
32+
.assert.containsText('p', 'Current route name: foo')
33+
.assert.containsText('.view', 'Foo')
2934
.end()
3035
}
3136
}

0 commit comments

Comments
 (0)