@@ -5,26 +5,32 @@ import { cleanPath } from './util/path'
55
66export function createRouteMap (
77 routes : Array < RouteConfig > ,
8+ oldPathList ?: Array < string > ,
89 oldPathMap ?: Dictionary < RouteRecord > ,
910 oldNameMap ?: Dictionary < RouteRecord >
1011) : {
12+ pathList : Array < string > ;
1113 pathMap : Dictionary < RouteRecord > ;
1214 nameMap : Dictionary < RouteRecord > ;
1315} {
16+ // the path list is used to control path matching priority
17+ const pathList : Array < string > = oldPathList || [ ]
1418 const pathMap : Dictionary < RouteRecord > = oldPathMap || Object . create ( null )
1519 const nameMap : Dictionary < RouteRecord > = oldNameMap || Object . create ( null )
1620
1721 routes . forEach ( route => {
18- addRouteRecord ( pathMap , nameMap , route )
22+ addRouteRecord ( pathList , pathMap , nameMap , route )
1923 } )
2024
2125 return {
26+ pathList ,
2227 pathMap,
2328 nameMap
2429 }
2530}
2631
2732function addRouteRecord (
33+ pathList : Array < string > ,
2834 pathMap : Dictionary < RouteRecord > ,
2935 nameMap : Dictionary < RouteRecord > ,
3036 route : RouteConfig ,
@@ -78,7 +84,7 @@ function addRouteRecord (
7884 const childMatchAs = matchAs
7985 ? cleanPath ( `${ matchAs } /${ child . path } ` )
8086 : undefined
81- addRouteRecord ( pathMap , nameMap , child , record , childMatchAs )
87+ addRouteRecord ( pathList , pathMap , nameMap , child , record , childMatchAs )
8288 } )
8389 }
8490
@@ -89,18 +95,19 @@ function addRouteRecord (
8995 path : alias ,
9096 children : route . children
9197 }
92- addRouteRecord ( pathMap , nameMap , aliasRoute , parent , record . path )
98+ addRouteRecord ( pathList , pathMap , nameMap , aliasRoute , parent , record . path )
9399 } )
94100 } else {
95101 const aliasRoute = {
96102 path : route . alias ,
97103 children : route . children
98104 }
99- addRouteRecord ( pathMap , nameMap , aliasRoute , parent , record . path )
105+ addRouteRecord ( pathList , pathMap , nameMap , aliasRoute , parent , record . path )
100106 }
101107 }
102108
103109 if ( ! pathMap [ record . path ] ) {
110+ pathList . push ( record . path )
104111 pathMap [ record . path ] = record
105112 }
106113
0 commit comments