@@ -3,19 +3,10 @@ import { derived } from 'svelte/store'
33import { routes } from './routes'
44import { pathname } from './path'
55
6- function map ( routes , matches = [ ] ) {
7- return Object . values ( routes ) . reverse ( ) . map ( e => [ e , matches ] )
8- }
9-
106// Search for matching route
11- function parse ( routes , pathname ) {
12- let stack = map ( routes )
13-
14- while ( stack . length ) {
15- let [ active , matches ] = stack . pop ( )
7+ function parse ( active , pathname , notRoot , matches = [ ] ) {
8+ if ( notRoot ) {
169 let params = active . $$pattern . match ( pathname )
17- matches = [ ...matches , active ]
18-
1910 if ( params ) {
2011 return ! active . $$redirect
2112 ? { active, params, matches }
@@ -25,8 +16,11 @@ function parse (routes, pathname) {
2516 window . dispatchEvent ( new Event ( 'hashchange' ) )
2617 } )
2718 }
19+ }
2820
29- stack = stack . concat ( map ( active , matches ) )
21+ for ( let e of Object . values ( active ) ) {
22+ let result = parse ( e , pathname , true , [ ...matches , e ] )
23+ if ( result ) return result
3024 }
3125}
3226
0 commit comments