Skip to content

Commit 0983678

Browse files
Remconl5887
Remco
authored andcommitted
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)
1 parent 5ee8d1e commit 0983678

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/state.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory, $
10961096
var state = findState(stateOrName, options.relative);
10971097
if (!isDefined(state)) return null;
10981098

1099-
params = inheritParams($stateParams, params || {}, $state.$current, state);
1099+
if (options.inherit) params = inheritParams($stateParams, params || {}, $state.$current, state);
1100+
11001101
var nav = (state && options.lossy) ? state.navigable : state;
11011102
var url = (nav && nav.url) ? nav.url.format(normalize(state.params, params || {})) : null;
11021103
if (!$locationProvider.html5Mode() && url) {

test/stateSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,13 @@ describe('state', function () {
643643
expect($state.href("about.person", { person: "bob" })).toEqual("#/about/bob");
644644
expect($state.href("about.person.item", { person: "bob", id: null })).toEqual("#/about/bob/");
645645
}));
646+
647+
it('inherit url parameters from current url', inject(function ($state) {
648+
initStateTo($state.get('root'), {param1: 1});
649+
expect($state.href("root", {}, {})).toEqual("#/root");
650+
expect($state.href("root", {}, {inherit:false})).toEqual("#/root");
651+
expect($state.href("root", {}, {inherit:true})).toEqual("#/root?param1=1");
652+
}));
646653

647654
it('generates absolute url when absolute is true', inject(function ($state) {
648655
expect($state.href("about.sidebar", null, { absolute: true })).toEqual("http://server/#/about");

0 commit comments

Comments
 (0)