File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11node_modules /
22coverage /
33npm-debug.log
4+ yarn.lock
Original file line number Diff line number Diff line change @@ -186,29 +186,33 @@ export default class RouteNode {
186186 const child = nodes [ i ] ;
187187
188188 // Partially match path
189- let match = child . parser . partialMatch ( pathSegment ) ;
189+ let match ;
190190 let remainingPath ;
191191
192- if ( ! match && trailingSlash ) {
193- // Try with optional trailing slash
194- match = child . parser . match ( pathSegment , true ) ;
195- remainingPath = '' ;
196- } else if ( match ) {
192+ if ( ! child . children . length ) {
193+ match = child . parser . test ( pathSegment , { trailingSlash } ) ;
194+ }
195+
196+ if ( ! match ) {
197+ match = child . parser . partialTest ( pathSegment ) ;
198+ }
199+
200+ if ( match ) {
197201 // Remove consumed segment from path
198- const consumedPath = child . parser . build ( match , { ignoreSearch : true } ) ;
202+ let consumedPath = child . parser . build ( match , { ignoreSearch : true } ) ;
203+ if ( trailingSlash && ! child . children . length ) {
204+ consumedPath = consumedPath . replace ( / \/ $ / , '' ) ;
205+ }
199206 remainingPath = pathSegment . replace ( consumedPath , '' ) ;
200207 const search = omit (
201208 getSearch ( pathSegment . replace ( consumedPath , '' ) ) ,
202209 child . parser . queryParams . concat ( child . parser . queryParamsBr )
203210 ) ;
204211 remainingPath = getPath ( remainingPath ) + ( search ? `?${ search } ` : '' ) ;
205-
206212 if ( trailingSlash && ! isRoot && remainingPath === '/' && ! / \/ $ / . test ( consumedPath ) ) {
207213 remainingPath = '' ;
208214 }
209- }
210215
211- if ( match ) {
212216 segments . push ( child ) ;
213217 Object . keys ( match ) . forEach ( param => segments . params [ param ] = match [ param ] ) ;
214218
Original file line number Diff line number Diff line change 5454 "yargs" : " ^4.8.1"
5555 },
5656 "dependencies" : {
57- "path-parser" : " ~1 .0.4 " ,
57+ "path-parser" : " 2 .0.0 " ,
5858 "search-params" : " ~1.3.0"
5959 }
6060}
Original file line number Diff line number Diff line change @@ -475,6 +475,16 @@ describe('RouteNode', function () {
475475 withoutMeta ( node . matchPath ( '/admin/?page=1' ) ) . should . eql ( { name : 'app.admin.users' , params : { page : '1' } } ) ;
476476 withoutMeta ( node . matchPath ( '/admin/' ) ) . should . eql ( { name : 'app.admin.users' , params : { } } ) ;
477477 } ) ;
478+
479+ it ( 'should fully match route nodes who have no children' , ( ) => {
480+ var node = new RouteNode ( '' , '' , [
481+ new RouteNode ( 'home' , '/home' ) ,
482+ new RouteNode ( 'section' , '/:section' )
483+ ] ) ;
484+
485+ withoutMeta ( node . matchPath ( '/homeland' ) ) . should . eql ( { name : 'section' , params : { section : 'homeland' } } ) ;
486+ withoutMeta ( node . matchPath ( '/hom' ) ) . should . eql ( { name : 'section' , params : { section : 'hom' } } ) ;
487+ } ) ;
478488} ) ;
479489
480490
You can’t perform that action at this time.
0 commit comments