@@ -33,44 +33,18 @@ export function createMatcher (routes: Array<RouteConfig>): Matcher {
33
33
const record = nameMap [ name ]
34
34
if ( record ) {
35
35
location . path = fillParams ( record . path , location . params , `named route "${ name } "` )
36
- return createRouteContext ( record , location , redirectedFrom )
36
+ return _createRoute ( record , location , redirectedFrom )
37
37
}
38
38
} else if ( location . path ) {
39
39
location . params = { }
40
40
for ( const path in pathMap ) {
41
41
if ( matchRoute ( path , location . params , location . path ) ) {
42
- return createRouteContext ( pathMap [ path ] , location , redirectedFrom )
42
+ return _createRoute ( pathMap [ path ] , location , redirectedFrom )
43
43
}
44
44
}
45
45
}
46
46
// no match
47
- return createRouteContext ( null , location )
48
- }
49
-
50
- function createRouteContext (
51
- record : ?RouteRecord ,
52
- location : Location ,
53
- redirectedFrom ?: Location
54
- ) : Route {
55
- if ( record && record . redirect ) {
56
- return redirect ( record , redirectedFrom || location )
57
- }
58
- if ( record && record . matchAs ) {
59
- return alias ( record , location , record . matchAs )
60
- }
61
- const route : Route = {
62
- name : location . name ,
63
- path : location . path || '/' ,
64
- hash : location . hash || '' ,
65
- query : location . query || { } ,
66
- params : location . params || { } ,
67
- fullPath : getFullPath ( location ) ,
68
- matched : record ? formatMatch ( record ) : [ ]
69
- }
70
- if ( redirectedFrom ) {
71
- route . redirectedFrom = getFullPath ( redirectedFrom )
72
- }
73
- return Object . freeze ( route )
47
+ return _createRoute ( null , location )
74
48
}
75
49
76
50
function redirect (
@@ -105,7 +79,7 @@ export function createMatcher (routes: Array<RouteConfig>): Matcher {
105
79
} , undefined , location )
106
80
} else {
107
81
warn ( false , `invalid redirect option: ${ JSON . stringify ( redirect ) } ` )
108
- return createRouteContext ( null , location )
82
+ return _createRoute ( null , location )
109
83
}
110
84
}
111
85
@@ -123,14 +97,48 @@ export function createMatcher (routes: Array<RouteConfig>): Matcher {
123
97
const matched = aliasedMatch . matched
124
98
const aliasedRecord = matched [ matched . length - 1 ]
125
99
location . params = aliasedMatch . params
126
- return createRouteContext ( aliasedRecord , location )
100
+ return _createRoute ( aliasedRecord , location )
101
+ }
102
+ return _createRoute ( null , location )
103
+ }
104
+
105
+ function _createRoute (
106
+ record : ?RouteRecord ,
107
+ location : Location ,
108
+ redirectedFrom ?: Location
109
+ ) : Route {
110
+ if ( record && record . redirect ) {
111
+ return redirect ( record , redirectedFrom || location )
127
112
}
128
- return createRouteContext ( null , location )
113
+ if ( record && record . matchAs ) {
114
+ return alias ( record , location , record . matchAs )
115
+ }
116
+ return createRoute ( record , location , redirectedFrom )
129
117
}
130
118
131
119
return match
132
120
}
133
121
122
+ export function createRoute (
123
+ record : ?RouteRecord ,
124
+ location : Location ,
125
+ redirectedFrom ? : Location
126
+ ) : Route {
127
+ const route : Route = {
128
+ name : location . name ,
129
+ path : location . path || '/' ,
130
+ hash : location . hash || '' ,
131
+ query : location . query || { } ,
132
+ params : location . params || { } ,
133
+ fullPath : getFullPath ( location ) ,
134
+ matched : record ? formatMatch ( record ) : [ ]
135
+ }
136
+ if ( redirectedFrom ) {
137
+ route . redirectedFrom = getFullPath ( redirectedFrom )
138
+ }
139
+ return Object . freeze ( route )
140
+ }
141
+
134
142
function matchRoute (
135
143
path : string ,
136
144
params : Object ,
0 commit comments