@@ -51,12 +51,27 @@ export function createMatcher (routes: Array<RouteConfig>): Matcher {
5151 record : RouteRecord ,
5252 location : Location
5353 ) : Route {
54- const { query, hash, params } = location
55- const { redirect : originalRedirect } = record
56- const redirect = typeof originalRedirect === 'function'
54+ const originalRedirect = record . redirect
55+ let redirect = typeof originalRedirect === 'function'
5756 ? originalRedirect ( createRoute ( record , location ) )
5857 : originalRedirect
59- const name = redirect && typeof redirect === 'object' && redirect . name
58+
59+ if ( typeof redirect === 'string' ) {
60+ redirect = { path : redirect }
61+ }
62+
63+ if ( ! redirect || typeof redirect !== 'object' ) {
64+ warn ( false , `invalid redirect option: ${ JSON . stringify ( redirect ) } ` )
65+ return _createRoute ( null , location )
66+ }
67+
68+ const re : Object = redirect
69+ const { name, path } = re
70+ let { query, hash, params } = location
71+ query = re . hasOwnProperty ( 'query' ) ? re . query : query
72+ hash = re . hasOwnProperty ( 'hash' ) ? re . hash : hash
73+ params = re . hasOwnProperty ( 'params' ) ? re . params : params
74+
6075 if ( name ) {
6176 // resolved named direct
6277 const targetRecord = nameMap [ name ]
@@ -68,15 +83,15 @@ export function createMatcher (routes: Array<RouteConfig>): Matcher {
6883 hash,
6984 params
7085 } , undefined , location )
71- } else if ( typeof redirect === 'string' ) {
86+ } else if ( path ) {
7287 // 1. resolve relative redirect
73- const rawPath = resolveRecordPath ( redirect , record )
88+ const rawPath = resolveRecordPath ( path , record )
7489 // 2. resolve params
75- const path = fillParams ( rawPath , params , `redirect route with path "${ rawPath } "` )
90+ const resolvedPath = fillParams ( rawPath , params , `redirect route with path "${ rawPath } "` )
7691 // 3. rematch with existing query and hash
7792 return match ( {
7893 _normalized : true ,
79- path,
94+ path : resolvedPath ,
8095 query,
8196 hash
8297 } , undefined , location )
0 commit comments