From 09836781f126c1c485b06551eb9cfd4fa0f45c35 Mon Sep 17 00:00:00 2001 From: Remco Date: Wed, 19 Mar 2014 11:34:18 +0100 Subject: [PATCH] fix($state): didn't comply to inherit parameter $state.href didn't comply to inherit parameter. Parameters aren't inherited anymore when inherit: false (default) --- src/state.js | 3 ++- test/stateSpec.js | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/state.js b/src/state.js index 5857deaa4..beb5efe94 100644 --- a/src/state.js +++ b/src/state.js @@ -1096,7 +1096,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $ var state = findState(stateOrName, options.relative); if (!isDefined(state)) return null; - params = inheritParams($stateParams, params || {}, $state.$current, state); + if (options.inherit) params = inheritParams($stateParams, params || {}, $state.$current, state); + var nav = (state && options.lossy) ? state.navigable : state; var url = (nav && nav.url) ? nav.url.format(normalize(state.params, params || {})) : null; if (!$locationProvider.html5Mode() && url) { diff --git a/test/stateSpec.js b/test/stateSpec.js index d91c49d53..537bddb74 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -643,6 +643,13 @@ describe('state', function () { expect($state.href("about.person", { person: "bob" })).toEqual("#/about/bob"); expect($state.href("about.person.item", { person: "bob", id: null })).toEqual("#/about/bob/"); })); + + it('inherit url parameters from current url', inject(function ($state) { + initStateTo($state.get('root'), {param1: 1}); + expect($state.href("root", {}, {})).toEqual("#/root"); + expect($state.href("root", {}, {inherit:false})).toEqual("#/root"); + expect($state.href("root", {}, {inherit:true})).toEqual("#/root?param1=1"); + })); it('generates absolute url when absolute is true', inject(function ($state) { expect($state.href("about.sidebar", null, { absolute: true })).toEqual("http://server/#/about");