1
1
/*!
2
- * vue-router v3.3.4
2
+ * vue-router v3.4.0
3
3
* (c) 2020 Evan You
4
4
* @license MIT
5
5
*/
@@ -19,14 +19,6 @@ function warn (condition, message) {
19
19
}
20
20
}
21
21
22
- function isError ( err ) {
23
- return Object . prototype . toString . call ( err ) . indexOf ( 'Error' ) > - 1
24
- }
25
-
26
- function isRouterError ( err , errorType ) {
27
- return isError ( err ) && err . _isRouter && ( errorType == null || err . type === errorType )
28
- }
29
-
30
22
function extend ( a , b ) {
31
23
for ( var key in b ) {
32
24
a [ key ] = b [ key ] ;
@@ -135,7 +127,7 @@ var View = {
135
127
} ;
136
128
137
129
var configProps = matched . props && matched . props [ name ] ;
138
- // save route and configProps in cachce
130
+ // save route and configProps in cache
139
131
if ( configProps ) {
140
132
extend ( cache [ name ] , {
141
133
route : route ,
@@ -217,7 +209,8 @@ function resolveQuery (
217
209
parsedQuery = { } ;
218
210
}
219
211
for ( var key in extraQuery ) {
220
- parsedQuery [ key ] = extraQuery [ key ] ;
212
+ var value = extraQuery [ key ] ;
213
+ parsedQuery [ key ] = Array . isArray ( value ) ? value . map ( function ( v ) { return '' + v ; } ) : '' + value ;
221
214
}
222
215
return parsedQuery
223
216
}
@@ -1906,6 +1899,88 @@ function runQueue (queue, fn, cb) {
1906
1899
step ( 0 ) ;
1907
1900
}
1908
1901
1902
+ var NavigationFailureType = {
1903
+ redirected : 2 ,
1904
+ aborted : 4 ,
1905
+ cancelled : 8 ,
1906
+ duplicated : 16
1907
+ } ;
1908
+
1909
+ function createNavigationRedirectedError ( from , to ) {
1910
+ return createRouterError (
1911
+ from ,
1912
+ to ,
1913
+ NavigationFailureType . redirected ,
1914
+ ( "Redirected when going from \"" + ( from . fullPath ) + "\" to \"" + ( stringifyRoute (
1915
+ to
1916
+ ) ) + "\" via a navigation guard." )
1917
+ )
1918
+ }
1919
+
1920
+ function createNavigationDuplicatedError ( from , to ) {
1921
+ var error = createRouterError (
1922
+ from ,
1923
+ to ,
1924
+ NavigationFailureType . duplicated ,
1925
+ ( "Avoided redundant navigation to current location: \"" + ( from . fullPath ) + "\"." )
1926
+ ) ;
1927
+ // backwards compatible with the first introduction of Errors
1928
+ error . name = 'NavigationDuplicated' ;
1929
+ return error
1930
+ }
1931
+
1932
+ function createNavigationCancelledError ( from , to ) {
1933
+ return createRouterError (
1934
+ from ,
1935
+ to ,
1936
+ NavigationFailureType . cancelled ,
1937
+ ( "Navigation cancelled from \"" + ( from . fullPath ) + "\" to \"" + ( to . fullPath ) + "\" with a new navigation." )
1938
+ )
1939
+ }
1940
+
1941
+ function createNavigationAbortedError ( from , to ) {
1942
+ return createRouterError (
1943
+ from ,
1944
+ to ,
1945
+ NavigationFailureType . aborted ,
1946
+ ( "Navigation aborted from \"" + ( from . fullPath ) + "\" to \"" + ( to . fullPath ) + "\" via a navigation guard." )
1947
+ )
1948
+ }
1949
+
1950
+ function createRouterError ( from , to , type , message ) {
1951
+ var error = new Error ( message ) ;
1952
+ error . _isRouter = true ;
1953
+ error . from = from ;
1954
+ error . to = to ;
1955
+ error . type = type ;
1956
+
1957
+ return error
1958
+ }
1959
+
1960
+ var propertiesToLog = [ 'params' , 'query' , 'hash' ] ;
1961
+
1962
+ function stringifyRoute ( to ) {
1963
+ if ( typeof to === 'string' ) { return to }
1964
+ if ( 'path' in to ) { return to . path }
1965
+ var location = { } ;
1966
+ propertiesToLog . forEach ( function ( key ) {
1967
+ if ( key in to ) { location [ key ] = to [ key ] ; }
1968
+ } ) ;
1969
+ return JSON . stringify ( location , null , 2 )
1970
+ }
1971
+
1972
+ function isError ( err ) {
1973
+ return Object . prototype . toString . call ( err ) . indexOf ( 'Error' ) > - 1
1974
+ }
1975
+
1976
+ function isNavigationFailure ( err , errorType ) {
1977
+ return (
1978
+ isError ( err ) &&
1979
+ err . _isRouter &&
1980
+ ( errorType == null || err . type === errorType )
1981
+ )
1982
+ }
1983
+
1909
1984
/* */
1910
1985
1911
1986
function resolveAsyncComponents ( matched ) {
@@ -2015,73 +2090,6 @@ function once (fn) {
2015
2090
}
2016
2091
}
2017
2092
2018
- var NavigationFailureType = {
2019
- redirected : 1 ,
2020
- aborted : 2 ,
2021
- cancelled : 3 ,
2022
- duplicated : 4
2023
- } ;
2024
-
2025
- function createNavigationRedirectedError ( from , to ) {
2026
- return createRouterError (
2027
- from ,
2028
- to ,
2029
- NavigationFailureType . redirected ,
2030
- ( "Redirected when going from \"" + ( from . fullPath ) + "\" to \"" + ( stringifyRoute (
2031
- to
2032
- ) ) + "\" via a navigation guard." )
2033
- )
2034
- }
2035
-
2036
- function createNavigationDuplicatedError ( from , to ) {
2037
- return createRouterError (
2038
- from ,
2039
- to ,
2040
- NavigationFailureType . duplicated ,
2041
- ( "Avoided redundant navigation to current location: \"" + ( from . fullPath ) + "\"." )
2042
- )
2043
- }
2044
-
2045
- function createNavigationCancelledError ( from , to ) {
2046
- return createRouterError (
2047
- from ,
2048
- to ,
2049
- NavigationFailureType . cancelled ,
2050
- ( "Navigation cancelled from \"" + ( from . fullPath ) + "\" to \"" + ( to . fullPath ) + "\" with a new navigation." )
2051
- )
2052
- }
2053
-
2054
- function createNavigationAbortedError ( from , to ) {
2055
- return createRouterError (
2056
- from ,
2057
- to ,
2058
- NavigationFailureType . aborted ,
2059
- ( "Navigation aborted from \"" + ( from . fullPath ) + "\" to \"" + ( to . fullPath ) + "\" via a navigation guard." )
2060
- )
2061
- }
2062
-
2063
- function createRouterError ( from , to , type , message ) {
2064
- var error = new Error ( message ) ;
2065
- error . _isRouter = true ;
2066
- error . from = from ;
2067
- error . to = to ;
2068
- error . type = type ;
2069
-
2070
- return error
2071
- }
2072
-
2073
- var propertiesToLog = [ 'params' , 'query' , 'hash' ] ;
2074
-
2075
- function stringifyRoute ( to ) {
2076
- if ( typeof to === 'string' ) { return to }
2077
- if ( 'path' in to ) { return to . path }
2078
- var location = { } ;
2079
- propertiesToLog . forEach ( function ( key ) {
2080
- if ( key in to ) { location [ key ] = to [ key ] ; }
2081
- } ) ;
2082
- return JSON . stringify ( location , null , 2 )
2083
- }
2084
-
2085
2093
/* */
2086
2094
2087
2095
var History = function History ( router , base ) {
@@ -2123,7 +2131,17 @@ History.prototype.transitionTo = function transitionTo (
2123
2131
) {
2124
2132
var this$1 = this ;
2125
2133
2126
- var route = this . router . match ( location , this . current ) ;
2134
+ var route ;
2135
+ // catch redirect option https://github.com/vuejs/vue-router/issues/3201
2136
+ try {
2137
+ route = this . router . match ( location , this . current ) ;
2138
+ } catch ( e ) {
2139
+ this . errorCbs . forEach ( function ( cb ) {
2140
+ cb ( e ) ;
2141
+ } ) ;
2142
+ // Exception should still be thrown
2143
+ throw e
2144
+ }
2127
2145
this . confirmTransition (
2128
2146
route ,
2129
2147
function ( ) {
@@ -2151,7 +2169,7 @@ History.prototype.transitionTo = function transitionTo (
2151
2169
this$1 . ready = true ;
2152
2170
// Initial redirection should still trigger the onReady onSuccess
2153
2171
// https://github.com/vuejs/vue-router/issues/3225
2154
- if ( ! isRouterError ( err , NavigationFailureType . redirected ) ) {
2172
+ if ( ! isNavigationFailure ( err , NavigationFailureType . redirected ) ) {
2155
2173
this$1 . readyErrorCbs . forEach ( function ( cb ) {
2156
2174
cb ( err ) ;
2157
2175
} ) ;
@@ -2173,7 +2191,7 @@ History.prototype.confirmTransition = function confirmTransition (route, onCompl
2173
2191
// changed after adding errors with
2174
2192
// https://github.com/vuejs/vue-router/pull/3047 before that change,
2175
2193
// redirect and aborted navigation would produce an err == null
2176
- if ( ! isRouterError ( err ) && isError ( err ) ) {
2194
+ if ( ! isNavigationFailure ( err ) && isError ( err ) ) {
2177
2195
if ( this$1 . errorCbs . length ) {
2178
2196
this$1 . errorCbs . forEach ( function ( cb ) {
2179
2197
cb ( err ) ;
@@ -2759,7 +2777,7 @@ var AbstractHistory = /*@__PURE__*/(function (History) {
2759
2777
this$1 . updateRoute ( route ) ;
2760
2778
} ,
2761
2779
function ( err ) {
2762
- if ( isRouterError ( err , NavigationFailureType . duplicated ) ) {
2780
+ if ( isNavigationFailure ( err , NavigationFailureType . duplicated ) ) {
2763
2781
this$1 . index = targetIndex ;
2764
2782
}
2765
2783
}
@@ -2780,8 +2798,6 @@ var AbstractHistory = /*@__PURE__*/(function (History) {
2780
2798
2781
2799
/* */
2782
2800
2783
-
2784
-
2785
2801
var VueRouter = function VueRouter ( options ) {
2786
2802
if ( options === void 0 ) options = { } ;
2787
2803
@@ -2794,7 +2810,8 @@ var VueRouter = function VueRouter (options) {
2794
2810
this . matcher = createMatcher ( options . routes || [ ] , this ) ;
2795
2811
2796
2812
var mode = options . mode || 'hash' ;
2797
- this . fallback = mode === 'history' && ! supportsPushState && options . fallback !== false ;
2813
+ this . fallback =
2814
+ mode === 'history' && ! supportsPushState && options . fallback !== false ;
2798
2815
if ( this . fallback ) {
2799
2816
mode = 'hash' ;
2800
2817
}
@@ -2822,11 +2839,7 @@ var VueRouter = function VueRouter (options) {
2822
2839
2823
2840
var prototypeAccessors = { currentRoute : { configurable : true } } ;
2824
2841
2825
- VueRouter . prototype . match = function match (
2826
- raw ,
2827
- current ,
2828
- redirectedFrom
2829
- ) {
2842
+ VueRouter . prototype . match = function match ( raw , current , redirectedFrom ) {
2830
2843
return this . matcher . match ( raw , current , redirectedFrom )
2831
2844
} ;
2832
2845
@@ -2837,11 +2850,12 @@ prototypeAccessors.currentRoute.get = function () {
2837
2850
VueRouter . prototype . init = function init ( app /* Vue component instance */ ) {
2838
2851
var this$1 = this ;
2839
2852
2840
- process . env . NODE_ENV !== 'production' && assert (
2841
- install . installed ,
2842
- "not installed. Make sure to call `Vue.use(VueRouter)` " +
2843
- "before creating root instance."
2844
- ) ;
2853
+ process . env . NODE_ENV !== 'production' &&
2854
+ assert (
2855
+ install . installed ,
2856
+ "not installed. Make sure to call `Vue.use(VueRouter)` " +
2857
+ "before creating root instance."
2858
+ ) ;
2845
2859
2846
2860
this . apps . push ( app ) ;
2847
2861
@@ -2873,10 +2887,24 @@ VueRouter.prototype.init = function init (app /* Vue component instance */) {
2873
2887
var history = this . history ;
2874
2888
2875
2889
if ( history instanceof HTML5History || history instanceof HashHistory ) {
2876
- var setupListeners = function ( ) {
2890
+ var handleInitialScroll = function ( routeOrError ) {
2891
+ var from = history . current ;
2892
+ var expectScroll = this$1 . options . scrollBehavior ;
2893
+ var supportsScroll = supportsPushState && expectScroll ;
2894
+
2895
+ if ( supportsScroll && 'fullPath' in routeOrError ) {
2896
+ handleScroll ( this$1 , routeOrError , from , false ) ;
2897
+ }
2898
+ } ;
2899
+ var setupListeners = function ( routeOrError ) {
2877
2900
history . setupListeners ( ) ;
2901
+ handleInitialScroll ( routeOrError ) ;
2878
2902
} ;
2879
- history . transitionTo ( history . getCurrentLocation ( ) , setupListeners , setupListeners ) ;
2903
+ history . transitionTo (
2904
+ history . getCurrentLocation ( ) ,
2905
+ setupListeners ,
2906
+ setupListeners
2907
+ ) ;
2880
2908
}
2881
2909
2882
2910
history . listen ( function ( route ) {
@@ -2953,11 +2981,14 @@ VueRouter.prototype.getMatchedComponents = function getMatchedComponents (to) {
2953
2981
if ( ! route ) {
2954
2982
return [ ]
2955
2983
}
2956
- return [ ] . concat . apply ( [ ] , route . matched . map ( function ( m ) {
2957
- return Object . keys ( m . components ) . map ( function ( key ) {
2958
- return m . components [ key ]
2984
+ return [ ] . concat . apply (
2985
+ [ ] ,
2986
+ route . matched . map ( function ( m ) {
2987
+ return Object . keys ( m . components ) . map ( function ( key ) {
2988
+ return m . components [ key ]
2989
+ } )
2959
2990
} )
2960
- } ) )
2991
+ )
2961
2992
} ;
2962
2993
2963
2994
VueRouter . prototype . resolve = function resolve (
@@ -2966,12 +2997,7 @@ VueRouter.prototype.resolve = function resolve (
2966
2997
append
2967
2998
) {
2968
2999
current = current || this . history . current ;
2969
- var location = normalizeLocation (
2970
- to ,
2971
- current ,
2972
- append ,
2973
- this
2974
- ) ;
3000
+ var location = normalizeLocation ( to , current , append , this ) ;
2975
3001
var route = this . match ( location , current ) ;
2976
3002
var fullPath = route . redirectedFrom || route . fullPath ;
2977
3003
var base = this . history . base ;
@@ -3009,7 +3035,9 @@ function createHref (base, fullPath, mode) {
3009
3035
}
3010
3036
3011
3037
VueRouter . install = install ;
3012
- VueRouter . version = '3.3.4' ;
3038
+ VueRouter . version = '3.4.0' ;
3039
+ VueRouter . isNavigationFailure = isNavigationFailure ;
3040
+ VueRouter . NavigationFailureType = NavigationFailureType ;
3013
3041
3014
3042
if ( inBrowser && window . Vue ) {
3015
3043
window . Vue . use ( VueRouter ) ;
0 commit comments