@@ -184,12 +184,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
184
184
}
185
185
186
186
// Normalize/filter parameters before we pass them to event handlers etc.
187
- var normalizedToParams = { } ;
188
- forEach ( to . params , function ( name ) {
189
- var value = toParams [ name ] ;
190
- normalizedToParams [ name ] = ( value != null ) ? String ( value ) : null ;
191
- } ) ;
192
- toParams = normalizedToParams ;
187
+ toParams = normalize ( to . params , toParams || { } ) ;
193
188
194
189
// Broadcast start event and cancel the transition if requested
195
190
if ( $rootScope . $broadcast ( '$stateChangeStart' , to . self , toParams , from . self , fromParams )
@@ -271,6 +266,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
271
266
return $state . $current . includes [ findState ( stateOrName ) . name ] ;
272
267
} ;
273
268
269
+ $state . href = function ( stateOrName , params ) {
270
+ var state = findState ( stateOrName ) , nav = state . navigable ;
271
+ if ( ! nav ) throw new Error ( "State '" + state + "' is not navigable" ) ;
272
+ return nav . url . format ( normalize ( state . params , params || { } ) ) ;
273
+ } ;
274
274
275
275
function resolveState ( state , params , paramsAreFiltered , inherited , dst ) {
276
276
// We need to track all the promises generated during the resolution process.
@@ -345,6 +345,16 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
345
345
} ) ;
346
346
}
347
347
348
+ function normalize ( keys , values ) {
349
+ var normalized = { } ;
350
+
351
+ forEach ( keys , function ( name ) {
352
+ var value = values [ name ] ;
353
+ normalized [ name ] = ( value != null ) ? String ( value ) : null ;
354
+ } ) ;
355
+ return normalized ;
356
+ }
357
+
348
358
function equalForKeys ( a , b , keys ) {
349
359
for ( var i = 0 ; i < keys . length ; i ++ ) {
350
360
var k = keys [ i ] ;
0 commit comments