@@ -5,26 +5,32 @@ import { cleanPath } from './util/path'
5
5
6
6
export function createRouteMap (
7
7
routes : Array < RouteConfig > ,
8
+ oldPathList ?: Array < string > ,
8
9
oldPathMap ?: Dictionary < RouteRecord > ,
9
10
oldNameMap ?: Dictionary < RouteRecord >
10
11
) : {
12
+ pathList : Array < string > ;
11
13
pathMap : Dictionary < RouteRecord > ;
12
14
nameMap : Dictionary < RouteRecord > ;
13
15
} {
16
+ // the path list is used to control path matching priority
17
+ const pathList : Array < string > = oldPathList || [ ]
14
18
const pathMap : Dictionary < RouteRecord > = oldPathMap || Object . create ( null )
15
19
const nameMap : Dictionary < RouteRecord > = oldNameMap || Object . create ( null )
16
20
17
21
routes . forEach ( route => {
18
- addRouteRecord ( pathMap , nameMap , route )
22
+ addRouteRecord ( pathList , pathMap , nameMap , route )
19
23
} )
20
24
21
25
return {
26
+ pathList ,
22
27
pathMap,
23
28
nameMap
24
29
}
25
30
}
26
31
27
32
function addRouteRecord (
33
+ pathList : Array < string > ,
28
34
pathMap : Dictionary < RouteRecord > ,
29
35
nameMap : Dictionary < RouteRecord > ,
30
36
route : RouteConfig ,
@@ -78,7 +84,7 @@ function addRouteRecord (
78
84
const childMatchAs = matchAs
79
85
? cleanPath ( `${ matchAs } /${ child . path } ` )
80
86
: undefined
81
- addRouteRecord ( pathMap , nameMap , child , record , childMatchAs )
87
+ addRouteRecord ( pathList , pathMap , nameMap , child , record , childMatchAs )
82
88
} )
83
89
}
84
90
@@ -89,18 +95,19 @@ function addRouteRecord (
89
95
path : alias ,
90
96
children : route . children
91
97
}
92
- addRouteRecord ( pathMap , nameMap , aliasRoute , parent , record . path )
98
+ addRouteRecord ( pathList , pathMap , nameMap , aliasRoute , parent , record . path )
93
99
} )
94
100
} else {
95
101
const aliasRoute = {
96
102
path : route . alias ,
97
103
children : route . children
98
104
}
99
- addRouteRecord ( pathMap , nameMap , aliasRoute , parent , record . path )
105
+ addRouteRecord ( pathList , pathMap , nameMap , aliasRoute , parent , record . path )
100
106
}
101
107
}
102
108
103
109
if ( ! pathMap [ record . path ] ) {
110
+ pathList . push ( record . path )
104
111
pathMap [ record . path ] = record
105
112
}
106
113
0 commit comments