@@ -184,12 +184,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
184184 }
185185
186186 // 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 || { } ) ;
193188
194189 // Broadcast start event and cancel the transition if requested
195190 if ( $rootScope . $broadcast ( '$stateChangeStart' , to . self , toParams , from . self , fromParams )
@@ -271,6 +266,11 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
271266 return $state . $current . includes [ findState ( stateOrName ) . name ] ;
272267 } ;
273268
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+ } ;
274274
275275 function resolveState ( state , params , paramsAreFiltered , inherited , dst ) {
276276 // We need to track all the promises generated during the resolution process.
@@ -345,6 +345,16 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
345345 } ) ;
346346 }
347347
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+
348358 function equalForKeys ( a , b , keys ) {
349359 for ( var i = 0 ; i < keys . length ; i ++ ) {
350360 var k = keys [ i ] ;
0 commit comments