File tree 5 files changed +93
-1
lines changed
5 files changed +93
-1
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ <h1>Vue Router Examples</h1>
17
17
< li > < a href ="redirect "> Redirect</ a > </ li >
18
18
< li > < a href ="route-props "> Route Props</ a > </ li >
19
19
< li > < a href ="route-alias "> Route Alias</ a > </ li >
20
+ < li > < a href ="route-params "> Route Params</ a > </ li >
20
21
< li > < a href ="transitions "> Transitions</ a > </ li >
21
22
< li > < a href ="data-fetching "> Data Fetching</ a > </ li >
22
23
< li > < a href ="navigation-guards "> Navigation Guards</ a > </ li >
Original file line number Diff line number Diff line change
1
+ import Vue from 'vue'
2
+ import VueRouter from 'vue-router'
3
+
4
+ Vue . use ( VueRouter )
5
+
6
+ const Log = {
7
+ template : `<div class="log">id: {{$route.params.id}}, type: {{$route.params.type}}</div>`
8
+ }
9
+
10
+ const Logs = {
11
+ template : `
12
+ <div>
13
+ <router-link :to="to" class="child-link">{{to.params.type}}</router-link>
14
+ <router-view></router-view>
15
+ </div>
16
+ ` ,
17
+ data ( ) {
18
+ return {
19
+ to : {
20
+ name : 'items.logs.type' ,
21
+ params : { type : 'info' }
22
+ }
23
+ }
24
+ }
25
+ }
26
+
27
+ const router = new VueRouter ( {
28
+ mode : 'history' ,
29
+ base : __dirname ,
30
+ routes : [
31
+ {
32
+ path : '/items/:id/logs' ,
33
+ component : Logs ,
34
+ children : [
35
+ {
36
+ path : ':type' ,
37
+ name : 'items.logs.type' ,
38
+ component : Log
39
+ }
40
+ ]
41
+ }
42
+ ]
43
+ } )
44
+
45
+ new Vue ( {
46
+ router,
47
+ template : `
48
+ <div id="app">
49
+ <h1>Route params</h1>
50
+ <ul>
51
+ <li><router-link to="/items/1/logs">item #1</router-link></li>
52
+ <li><router-link to="/items/2/logs">item #2</router-link></li>
53
+ </ul>
54
+ <router-view class="view"></router-view>
55
+ </div>
56
+ `
57
+ } ) . $mount ( '#app' )
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < link rel ="stylesheet " href ="/global.css ">
3
+ < a href ="/ "> ← Examples index</ a >
4
+ < div id ="app "> </ div >
5
+ < script src ="/__build__/shared.chunk.js "> </ script >
6
+ < script src ="/__build__/route-params.js "> </ script >
Original file line number Diff line number Diff line change @@ -18,7 +18,12 @@ export function normalizeLocation (
18
18
if ( next . _normalized ) {
19
19
return next
20
20
} else if ( next . name ) {
21
- return extend ( { } , raw )
21
+ next = extend ( { } , raw )
22
+ const params = next . params
23
+ if ( params && typeof params === 'object' ) {
24
+ next . params = extend ( { } , params )
25
+ }
26
+ return next
22
27
}
23
28
24
29
// relative params
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ 'route-params' : function ( browser ) {
3
+ browser
4
+ . url ( 'http://localhost:8080/route-params/' )
5
+ . waitForElementVisible ( '#app' , 1000 )
6
+ . assert . count ( 'li a' , 2 )
7
+
8
+ // https://github.com/vuejs/vue-router/issues/2800
9
+ . click ( 'li:nth-child(1) a' )
10
+ . assert . urlEquals ( 'http://localhost:8080/route-params/items/1/logs' )
11
+ . click ( '.child-link' )
12
+ . assert . urlEquals ( 'http://localhost:8080/route-params/items/1/logs/info' )
13
+ . assert . containsText ( '.log' , 'id: 1, type: info' )
14
+
15
+ . click ( 'li:nth-child(2) a' )
16
+ . assert . urlEquals ( 'http://localhost:8080/route-params/items/2/logs' )
17
+ . click ( '.child-link' )
18
+ . assert . urlEquals ( 'http://localhost:8080/route-params/items/2/logs/info' )
19
+ . assert . containsText ( '.log' , 'id: 2, type: info' )
20
+
21
+ . end ( )
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments