File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -159,7 +159,15 @@ export default class RouteNode {
159159 }
160160
161161 buildPathFromSegments ( segments , params = { } ) {
162- return segments ? segments . map ( segment => segment . parser . build ( params ) ) . join ( '' ) : null
162+ let searchPart = segments
163+ . filter ( s => s . parser . hasQueryParams )
164+ . map ( s => s . parser . queryParams )
165+ . reduce ( ( queryParams , params ) => queryParams . concat ( params ) )
166+ . filter ( p => Object . keys ( params ) . indexOf ( p ) !== - 1 )
167+ . map ( p => p + '=' + params [ p ] )
168+ . join ( '&' )
169+
170+ return segments ? segments . map ( segment => segment . parser . build ( params , { ignoreSearch : true } ) ) . join ( '' ) + ( searchPart ? '?' + searchPart : '' ) : null
163171 }
164172
165173 buildPath ( routeName , params = { } ) {
Original file line number Diff line number Diff line change 3232 "async" : " ^1.3.0"
3333 },
3434 "dependencies" : {
35- "path-parser" : " ~0.2.4 "
35+ "path-parser" : " ~0.3.0 "
3636 }
3737}
Original file line number Diff line number Diff line change @@ -123,6 +123,21 @@ describe('RouteNode', function () {
123123 should . not . exists ( node . matchPath ( '/users/view/profile/1' ) ) ;
124124 } ) ;
125125
126+ it ( 'should find build a path with nested query parameters' , function ( ) {
127+ var node = new RouteNode ( '' , '' , [
128+ new RouteNode ( 'grandParent' , '/grand-parent?nickame' , [
129+ new RouteNode ( 'parent' , '/parent?name' , [
130+ new RouteNode ( 'child' , '/child?age' )
131+ ] )
132+ ] )
133+ ] ) ;
134+
135+ node . buildPath ( 'grandParent' , { nickame : 'gran' } ) . should . equal ( '/grand-parent?nickame=gran' ) ;
136+ node . buildPath ( 'grandParent.parent' , { nickame : 'gran' , name : 'maman' } ) . should . equal ( '/grand-parent/parent?nickame=gran&name=maman' ) ;
137+ node . buildPath ( 'grandParent.parent' , { nickame : 'gran' } ) . should . equal ( '/grand-parent/parent?nickame=gran' ) ;
138+ node . buildPath ( 'grandParent.parent' , { name : 'maman' } ) . should . equal ( '/grand-parent/parent?name=maman' ) ;
139+ } ) ;
140+
126141 it ( 'should find a nested route by matching a path with a splat' , function ( ) {
127142 var node = getRoutesWithSplat ( ) ;
128143 // Building paths
You can’t perform that action at this time.
0 commit comments