11/**
2- * vue-router v2.5.3
2+ * vue-router v2.6.0
33 * (c) 2017 Evan You
44 * @license MIT
55 */
@@ -47,7 +47,7 @@ var View = {
4747 // has been toggled inactive but kept-alive.
4848 var depth = 0 ;
4949 var inactive = false ;
50- while ( parent ) {
50+ while ( parent && parent . _routerRoot !== parent ) {
5151 if ( parent . $vnode && parent . $vnode . data . routerView ) {
5252 depth ++ ;
5353 }
@@ -198,7 +198,7 @@ function stringifyQuery (obj) {
198198
199199 if ( Array . isArray ( val ) ) {
200200 var result = [ ] ;
201- val . slice ( ) . forEach ( function ( val2 ) {
201+ val . forEach ( function ( val2 ) {
202202 if ( val2 === undefined ) {
203203 return
204204 }
@@ -302,7 +302,15 @@ function isObjectEqual (a, b) {
302302 if ( aKeys . length !== bKeys . length ) {
303303 return false
304304 }
305- return aKeys . every ( function ( key ) { return String ( a [ key ] ) === String ( b [ key ] ) ; } )
305+ return aKeys . every ( function ( key ) {
306+ var aVal = a [ key ] ;
307+ var bVal = b [ key ] ;
308+ // check nested equality
309+ if ( typeof aVal === 'object' && typeof bVal === 'object' ) {
310+ return isObjectEqual ( aVal , bVal )
311+ }
312+ return String ( aVal ) === String ( bVal )
313+ } )
306314}
307315
308316function isIncludedRoute ( current , target ) {
@@ -433,7 +441,7 @@ var Link = {
433441
434442function guardEvent ( e ) {
435443 // don't redirect with control keys
436- if ( e . metaKey || e . ctrlKey || e . shiftKey ) { return }
444+ if ( e . metaKey || e . altKey || e . ctrlKey || e . shiftKey ) { return }
437445 // don't redirect when preventDefault called
438446 if ( e . defaultPrevented ) { return }
439447 // don't redirect on right click
@@ -473,14 +481,6 @@ function install (Vue) {
473481
474482 _Vue = Vue ;
475483
476- Object . defineProperty ( Vue . prototype , '$router' , {
477- get : function get ( ) { return this . $root . _router }
478- } ) ;
479-
480- Object . defineProperty ( Vue . prototype , '$route' , {
481- get : function get ( ) { return this . $root . _route }
482- } ) ;
483-
484484 var isDef = function ( v ) { return v !== undefined ; } ;
485485
486486 var registerInstance = function ( vm , callVal ) {
@@ -493,9 +493,12 @@ function install (Vue) {
493493 Vue . mixin ( {
494494 beforeCreate : function beforeCreate ( ) {
495495 if ( isDef ( this . $options . router ) ) {
496+ this . _routerRoot = this ;
496497 this . _router = this . $options . router ;
497498 this . _router . init ( this ) ;
498499 Vue . util . defineReactive ( this , '_route' , this . _router . history . current ) ;
500+ } else {
501+ this . _routerRoot = ( this . $parent && this . $parent . _routerRoot ) || this ;
499502 }
500503 registerInstance ( this , this ) ;
501504 } ,
@@ -504,6 +507,14 @@ function install (Vue) {
504507 }
505508 } ) ;
506509
510+ Object . defineProperty ( Vue . prototype , '$router' , {
511+ get : function get ( ) { return this . _routerRoot . _router }
512+ } ) ;
513+
514+ Object . defineProperty ( Vue . prototype , '$route' , {
515+ get : function get ( ) { return this . _routerRoot . _route }
516+ } ) ;
517+
507518 Vue . component ( 'router-view' , View ) ;
508519 Vue . component ( 'router-link' , Link ) ;
509520
@@ -1096,9 +1107,15 @@ function addRouteRecord (
10961107 }
10971108
10981109 var normalizedPath = normalizePath ( path , parent ) ;
1110+ var pathToRegexpOptions = route . pathToRegexpOptions || { } ;
1111+
1112+ if ( typeof route . caseSensitive === 'boolean' ) {
1113+ pathToRegexpOptions . sensitive = route . caseSensitive ;
1114+ }
1115+
10991116 var record = {
11001117 path : normalizedPath ,
1101- regex : compileRouteRegex ( normalizedPath ) ,
1118+ regex : compileRouteRegex ( normalizedPath , pathToRegexpOptions ) ,
11021119 components : route . components || { default : route . component } ,
11031120 instances : { } ,
11041121 name : name ,
@@ -1115,11 +1132,11 @@ function addRouteRecord (
11151132 } ;
11161133
11171134 if ( route . children ) {
1118- // Warn if route is named and has a default child route.
1135+ // Warn if route is named, does not redirect and has a default child route.
11191136 // If users navigate to this route by name, the default child will
11201137 // not be rendered (GH Issue #629)
11211138 if ( process . env . NODE_ENV !== 'production' ) {
1122- if ( route . name && route . children . some ( function ( child ) { return / ^ \/ ? $ / . test ( child . path ) ; } ) ) {
1139+ if ( route . name && ! route . redirect && route . children . some ( function ( child ) { return / ^ \/ ? $ / . test ( child . path ) ; } ) ) {
11231140 warn (
11241141 false ,
11251142 "Named Route '" + ( route . name ) + "' has a default child route. " +
@@ -1139,21 +1156,24 @@ function addRouteRecord (
11391156 }
11401157
11411158 if ( route . alias !== undefined ) {
1142- if ( Array . isArray ( route . alias ) ) {
1143- route . alias . forEach ( function ( alias ) {
1144- var aliasRoute = {
1145- path : alias ,
1146- children : route . children
1147- } ;
1148- addRouteRecord ( pathList , pathMap , nameMap , aliasRoute , parent , record . path ) ;
1149- } ) ;
1150- } else {
1159+ var aliases = Array . isArray ( route . alias )
1160+ ? route . alias
1161+ : [ route . alias ] ;
1162+
1163+ aliases . forEach ( function ( alias ) {
11511164 var aliasRoute = {
1152- path : route . alias ,
1165+ path : alias ,
11531166 children : route . children
11541167 } ;
1155- addRouteRecord ( pathList , pathMap , nameMap , aliasRoute , parent , record . path ) ;
1156- }
1168+ addRouteRecord (
1169+ pathList ,
1170+ pathMap ,
1171+ nameMap ,
1172+ aliasRoute ,
1173+ parent ,
1174+ record . path || '/' // matchAs
1175+ ) ;
1176+ } ) ;
11571177 }
11581178
11591179 if ( ! pathMap [ record . path ] ) {
@@ -1174,8 +1194,8 @@ function addRouteRecord (
11741194 }
11751195}
11761196
1177- function compileRouteRegex ( path ) {
1178- var regex = index ( path ) ;
1197+ function compileRouteRegex ( path , pathToRegexpOptions ) {
1198+ var regex = index ( path , [ ] , pathToRegexpOptions ) ;
11791199 if ( process . env . NODE_ENV !== 'production' ) {
11801200 var keys = { } ;
11811201 regex . keys . forEach ( function ( key ) {
@@ -1216,7 +1236,7 @@ function normalizeLocation (
12161236 if ( current . name ) {
12171237 next . name = current . name ;
12181238 next . params = params ;
1219- } else if ( current . matched ) {
1239+ } else if ( current . matched . length ) {
12201240 var rawPath = current . matched [ current . matched . length - 1 ] . path ;
12211241 next . path = fillParams ( rawPath , params , ( "path " + ( current . path ) ) ) ;
12221242 } else if ( process . env . NODE_ENV !== 'production' ) {
@@ -1286,6 +1306,7 @@ function createMatcher (
12861306 if ( process . env . NODE_ENV !== 'production' ) {
12871307 warn ( record , ( "Route with name '" + name + "' does not exist" ) ) ;
12881308 }
1309+ if ( ! record ) { return _createRoute ( null , location ) }
12891310 var paramNames = record . regex . keys
12901311 . filter ( function ( key ) { return ! key . optional ; } )
12911312 . map ( function ( key ) { return key . name ; } ) ;
@@ -1496,7 +1517,9 @@ function handleScroll (
14961517 if ( isObject && typeof shouldScroll . selector === 'string' ) {
14971518 var el = document . querySelector ( shouldScroll . selector ) ;
14981519 if ( el ) {
1499- position = getElementPosition ( el ) ;
1520+ var offset = shouldScroll . offset && typeof shouldScroll . offset === 'object' ? shouldScroll . offset : { } ;
1521+ offset = normalizeOffset ( offset ) ;
1522+ position = getElementPosition ( el , offset ) ;
15001523 } else if ( isValidPosition ( shouldScroll ) ) {
15011524 position = normalizePosition ( shouldScroll ) ;
15021525 }
@@ -1527,13 +1550,13 @@ function getScrollPosition () {
15271550 }
15281551}
15291552
1530- function getElementPosition ( el ) {
1553+ function getElementPosition ( el , offset ) {
15311554 var docEl = document . documentElement ;
15321555 var docRect = docEl . getBoundingClientRect ( ) ;
15331556 var elRect = el . getBoundingClientRect ( ) ;
15341557 return {
1535- x : elRect . left - docRect . left ,
1536- y : elRect . top - docRect . top
1558+ x : elRect . left - docRect . left - offset . x ,
1559+ y : elRect . top - docRect . top - offset . y
15371560 }
15381561}
15391562
@@ -1548,6 +1571,13 @@ function normalizePosition (obj) {
15481571 }
15491572}
15501573
1574+ function normalizeOffset ( obj ) {
1575+ return {
1576+ x : isNumber ( obj . x ) ? obj . x : 0 ,
1577+ y : isNumber ( obj . y ) ? obj . y : 0
1578+ }
1579+ }
1580+
15511581function isNumber ( v ) {
15521582 return typeof v === 'number'
15531583}
@@ -1800,6 +1830,8 @@ function normalizeBase (base) {
18001830 // respect <base> tag
18011831 var baseEl = document . querySelector ( 'base' ) ;
18021832 base = ( baseEl && baseEl . getAttribute ( 'href' ) ) || '/' ;
1833+ // strip full URL origin
1834+ base = base . replace ( / ^ h t t p s ? : \/ \/ [ ^ \/ ] + / , '' ) ;
18031835 } else {
18041836 base = '/' ;
18051837 }
@@ -2010,9 +2042,12 @@ function flatten (arr) {
20102042function once ( fn ) {
20112043 var called = false ;
20122044 return function ( ) {
2045+ var args = [ ] , len = arguments . length ;
2046+ while ( len -- ) args [ len ] = arguments [ len ] ;
2047+
20132048 if ( called ) { return }
20142049 called = true ;
2015- return fn . apply ( this , arguments )
2050+ return fn . apply ( this , args )
20162051 }
20172052}
20182053
@@ -2036,9 +2071,10 @@ var HTML5History = (function (History$$1) {
20362071 }
20372072
20382073 window . addEventListener ( 'popstate' , function ( e ) {
2074+ var current = this$1 . current ;
20392075 this$1 . transitionTo ( getLocation ( this$1 . base ) , function ( route ) {
20402076 if ( expectScroll ) {
2041- handleScroll ( router , route , this$1 . current , true ) ;
2077+ handleScroll ( router , route , current , true ) ;
20422078 }
20432079 } ) ;
20442080 } ) ;
@@ -2194,10 +2230,10 @@ function pushHash (path) {
21942230}
21952231
21962232function replaceHash ( path ) {
2197- var i = window . location . href . indexOf ( '#' ) ;
2198- window . location . replace (
2199- window . location . href . slice ( 0 , i >= 0 ? i : 0 ) + '#' + path
2200- ) ;
2233+ var href = window . location . href ;
2234+ var i = href . indexOf ( '#' ) ;
2235+ var base = i >= 0 ? href . slice ( 0 , i ) : href ;
2236+ window . location . replace ( ( base + "#" + path ) ) ;
22012237}
22022238
22032239/* */
@@ -2273,7 +2309,7 @@ var VueRouter = function VueRouter (options) {
22732309 this . matcher = createMatcher ( options . routes || [ ] , this ) ;
22742310
22752311 var mode = options . mode || 'hash' ;
2276- this . fallback = mode === 'history' && ! supportsPushState ;
2312+ this . fallback = mode === 'history' && ! supportsPushState && options . fallback !== false ;
22772313 if ( this . fallback ) {
22782314 mode = 'hash' ;
22792315 }
@@ -2457,7 +2493,7 @@ function createHref (base, fullPath, mode) {
24572493}
24582494
24592495VueRouter . install = install ;
2460- VueRouter . version = '2.5.3 ' ;
2496+ VueRouter . version = '2.6.0 ' ;
24612497
24622498if ( inBrowser && window . Vue ) {
24632499 window . Vue . use ( VueRouter ) ;
0 commit comments