@@ -48,18 +48,14 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
48
48
49
49
// Build a URLMatcher if necessary, either via a relative or absolute URL
50
50
url : function ( state ) {
51
- var url = state . url ;
51
+ var url = state . url , config = { params : state . params || { } } ;
52
52
53
53
if ( isString ( url ) ) {
54
- if ( url . charAt ( 0 ) == '^' ) {
55
- return $urlMatcherFactory . compile ( url . substring ( 1 ) ) ;
56
- }
57
- return ( state . parent . navigable || root ) . url . concat ( url ) ;
54
+ if ( url . charAt ( 0 ) == '^' ) return $urlMatcherFactory . compile ( url . substring ( 1 ) , config ) ;
55
+ return ( state . parent . navigable || root ) . url . concat ( url , config ) ;
58
56
}
59
57
60
- if ( $urlMatcherFactory . isMatcher ( url ) || url == null ) {
61
- return url ;
62
- }
58
+ if ( ! url || $urlMatcherFactory . isMatcher ( url ) ) return url ;
63
59
throw new Error ( "Invalid url '" + url + "' in state '" + state + "'" ) ;
64
60
} ,
65
61
@@ -71,10 +67,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
71
67
// Derive parameters for this state and ensure they're a super-set of parent's parameters
72
68
params : function ( state ) {
73
69
if ( ! state . params ) {
74
- return state . url ? state . url . parameters ( ) : state . parent . params ;
70
+ return state . url ? state . url . params : state . parent . params ;
75
71
}
76
- if ( ! isArray ( state . params ) ) throw new Error ( "Invalid params in state '" + state + "'" ) ;
77
- if ( state . url ) throw new Error ( "Both params and url specicified in state '" + state + "'" ) ;
78
72
return state . params ;
79
73
} ,
80
74
@@ -94,16 +88,18 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
94
88
} ,
95
89
96
90
ownParams : function ( state ) {
91
+ state . params = state . params || { } ;
92
+
97
93
if ( ! state . parent ) {
98
- return state . params ;
94
+ return objectKeys ( state . params ) ;
99
95
}
100
- var paramNames = { } ; forEach ( state . params , function ( p ) { paramNames [ p ] = true ; } ) ;
96
+ var paramNames = { } ; forEach ( state . params , function ( v , k ) { paramNames [ k ] = true ; } ) ;
101
97
102
- forEach ( state . parent . params , function ( p ) {
103
- if ( ! paramNames [ p ] ) {
104
- throw new Error ( "Missing required parameter '" + p + "' in state '" + state . name + "'" ) ;
98
+ forEach ( state . parent . params , function ( v , k ) {
99
+ if ( ! paramNames [ k ] ) {
100
+ throw new Error ( "Missing required parameter '" + k + "' in state '" + state . name + "'" ) ;
105
101
}
106
- paramNames [ p ] = false ;
102
+ paramNames [ k ] = false ;
107
103
} ) ;
108
104
var ownParams = [ ] ;
109
105
@@ -782,8 +778,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
782
778
toState = findState ( to , options . relative ) ;
783
779
784
780
if ( ! isDefined ( toState ) ) {
785
- if ( options . relative ) throw new Error ( "Could not resolve '" + to + "' from state '" + options . relative + "'" ) ;
786
- throw new Error ( "No such state '" + to + "'" ) ;
781
+ if ( ! options . relative ) throw new Error ( "No such state '" + to + "'" ) ;
782
+ throw new Error ( "Could not resolve '" + to + "' from state '" + options . relative + "'" ) ;
787
783
}
788
784
}
789
785
if ( toState [ abstractKey ] ) throw new Error ( "Cannot transition to abstract state '" + to + "'" ) ;
@@ -808,14 +804,14 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
808
804
// TODO: We may not want to bump 'transition' if we're called from a location change
809
805
// that we've initiated ourselves, because we might accidentally abort a legitimate
810
806
// transition initiated from code?
811
- if ( shouldTriggerReload ( to , from , locals , options ) ) {
807
+ if ( shouldTriggerReload ( to , from , locals , options ) ) {
812
808
if ( to . self . reloadOnSearch !== false ) $urlRouter . update ( ) ;
813
809
$state . transition = null ;
814
810
return $q . when ( $state . current ) ;
815
811
}
816
812
817
- // Normalize/filter parameters before we pass them to event handlers etc.
818
- toParams = normalize ( to . params , toParams || { } ) ;
813
+ // Filter parameters before we pass them to event handlers etc.
814
+ toParams = filterByKeys ( objectKeys ( to . params ) , toParams || { } ) ;
819
815
820
816
// Broadcast start event and cancel the transition if requested
821
817
if ( options . notify ) {
@@ -1090,7 +1086,12 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
1090
1086
* @returns {string } compiled state url
1091
1087
*/
1092
1088
$state . href = function href ( stateOrName , params , options ) {
1093
- options = extend ( { lossy : true , inherit : false , absolute : false , relative : $state . $current } , options || { } ) ;
1089
+ options = extend ( {
1090
+ lossy : true ,
1091
+ inherit : false ,
1092
+ absolute : false ,
1093
+ relative : $state . $current
1094
+ } , options || { } ) ;
1094
1095
1095
1096
var state = findState ( stateOrName , options . relative ) ;
1096
1097
@@ -1102,7 +1103,9 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
1102
1103
if ( ! nav || ! nav . url ) {
1103
1104
return null ;
1104
1105
}
1105
- return $urlRouter . href ( nav . url , normalize ( state . params , params || { } ) , { absolute : options . absolute } ) ;
1106
+ return $urlRouter . href ( nav . url , filterByKeys ( objectKeys ( state . params ) , params || { } ) , {
1107
+ absolute : options . absolute
1108
+ } ) ;
1106
1109
} ;
1107
1110
1108
1111
/**
@@ -1132,7 +1135,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
1132
1135
// necessary. In addition to being available to the controller and onEnter/onExit callbacks,
1133
1136
// we also need $stateParams to be available for any $injector calls we make during the
1134
1137
// dependency resolution process.
1135
- var $stateParams = ( paramsAreFiltered ) ? params : filterByKeys ( state . params , params ) ;
1138
+ var $stateParams = ( paramsAreFiltered ) ? params : filterByKeys ( objectKeys ( state . params ) , params ) ;
1136
1139
var locals = { $stateParams : $stateParams } ;
1137
1140
1138
1141
// Resolve 'global' dependencies for the state, i.e. those not specific to a view.
0 commit comments