import { Location } from 'history' ; import { parse } from 'query-string' ; import { createRouterState , Route , RouterState } from '../stores' ; import { matchUrl } from './matchUrl' ; export const createMatchingRouterState = ( location , routes , queryParseOptions ? ) : RouterState | undefined => { for ( let rIndex = 0 ; rIndex < routes . length ; rIndex ++ ) { const route = routes [ rIndex ] ; const patterns = route . altPatterns ? [ route . pattern ] . concat ( route . altPatterns ) : [ route . pattern ] ; for ( let pIndex = 0 ; pIndex < patterns . length ; pIndex ++ ) { const params = matchUrl ( location . pathname , patterns [ pIndex ] ) ; if ( params ) { const queryParams = parse ( location . search , queryParseOptions ) ; return createRouterState ( route . name , { params , queryParams } ) ; } } } return undefined ; } ;