@@ -33,44 +33,18 @@ export function createMatcher (routes: Array<RouteConfig>): Matcher {
3333 const record = nameMap [ name ]
3434 if ( record ) {
3535 location . path = fillParams ( record . path , location . params , `named route "${ name } "` )
36- return createRouteContext ( record , location , redirectedFrom )
36+ return _createRoute ( record , location , redirectedFrom )
3737 }
3838 } else if ( location . path ) {
3939 location . params = { }
4040 for ( const path in pathMap ) {
4141 if ( matchRoute ( path , location . params , location . path ) ) {
42- return createRouteContext ( pathMap [ path ] , location , redirectedFrom )
42+ return _createRoute ( pathMap [ path ] , location , redirectedFrom )
4343 }
4444 }
4545 }
4646 // 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 )
7448 }
7549
7650 function redirect (
@@ -105,7 +79,7 @@ export function createMatcher (routes: Array<RouteConfig>): Matcher {
10579 } , undefined , location )
10680 } else {
10781 warn ( false , `invalid redirect option: ${ JSON . stringify ( redirect ) } ` )
108- return createRouteContext ( null , location )
82+ return _createRoute ( null , location )
10983 }
11084 }
11185
@@ -123,14 +97,48 @@ export function createMatcher (routes: Array<RouteConfig>): Matcher {
12397 const matched = aliasedMatch . matched
12498 const aliasedRecord = matched [ matched . length - 1 ]
12599 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 )
127112 }
128- return createRouteContext ( null , location )
113+ if ( record && record . matchAs ) {
114+ return alias ( record , location , record . matchAs )
115+ }
116+ return createRoute ( record , location , redirectedFrom )
129117 }
130118
131119 return match
132120}
133121
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+
134142function matchRoute (
135143 path : string ,
136144 params : Object ,
0 commit comments