File tree Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Expand file tree Collapse file tree 2 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,8 @@ DynamicSegment.prototype = {
5959 } ,
6060
6161 generate : function ( params ) {
62- return params [ this . name ] || ":" + this . name ;
62+ var val = params [ this . name ] ;
63+ return val == null ? ":" + this . name : val ;
6364 }
6465} ;
6566
@@ -74,7 +75,8 @@ StarSegment.prototype = {
7475 } ,
7576
7677 generate : function ( params ) {
77- return params [ this . name ] || ":" + this . name ;
78+ var val = params [ this . name ] ;
79+ return val == null ? ":" + this . name : val ;
7880 }
7981} ;
8082
Original file line number Diff line number Diff line change @@ -1108,3 +1108,43 @@ describe('Core', function () {
11081108 target . dispatchEvent ( e )
11091109 }
11101110} )
1111+
1112+ describe ( 'Stringify Path' , function ( ) {
1113+
1114+ var router
1115+ beforeEach ( function ( ) {
1116+ router = new Router ( { abstract : true } )
1117+ } )
1118+
1119+ it ( 'plain string' , function ( ) {
1120+ expect ( router . _stringifyPath ( 'a' ) ) . toBe ( 'a' )
1121+ } )
1122+
1123+ it ( 'object path' , function ( ) {
1124+ expect ( router . _stringifyPath ( { path : '/hi' } ) ) . toBe ( '/hi' )
1125+ expect ( router . _stringifyPath ( { path : '/hi' , query : { a : 1 } } ) ) . toBe ( '/hi?a=1' )
1126+ expect ( router . _stringifyPath ( { path : '/hi' , query : { a : 1 , b : 2 } } ) ) . toBe ( '/hi?a=1&b=2' )
1127+ expect ( router . _stringifyPath ( { path : '/hi?c=3' , query : { a : 1 , b : 2 } } ) ) . toBe ( '/hi?c=3&a=1&b=2' )
1128+ } )
1129+
1130+ it ( 'named route' , function ( ) {
1131+ router . map ( {
1132+ '/test/:id' : {
1133+ name : 'a' ,
1134+ component : { }
1135+ }
1136+ } )
1137+ expect ( router . _stringifyPath ( { name : 'a' } ) ) . toBe ( '/test/:id' )
1138+ expect ( router . _stringifyPath ( { name : 'a' , params : { id : 0 } } ) ) . toBe ( '/test/0' )
1139+ expect ( router . _stringifyPath ( { name : 'a' , params : { id : 'hi' } } ) ) . toBe ( '/test/hi' )
1140+ } )
1141+
1142+ it ( 'named route not found should throw error' , function ( ) {
1143+ expect ( function ( ) {
1144+ router . _stringifyPath ( {
1145+ name : 'a'
1146+ } )
1147+ } ) . toThrow ( )
1148+ } )
1149+
1150+ } )
You can’t perform that action at this time.
0 commit comments