Skip to content

Commit

Permalink
fix($state): didn't comply to inherit parameter
Browse files Browse the repository at this point in the history
$state.href didn't comply to inherit parameter. Parameters aren't
inherited anymore when inherit: false (default)
  • Loading branch information
Remco authored and nl5887 committed Mar 20, 2014
1 parent 5ee8d1e commit 0983678
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions test/stateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 0983678

Please sign in to comment.