Skip to content

Commit

Permalink
Merge pull request #970 from dutchcoders/master
Browse files Browse the repository at this point in the history
$state.href inherit parameter fix
  • Loading branch information
nateabele committed Mar 20, 2014
2 parents a89be9a + 0983678 commit f5c426b
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 @@ -1099,7 +1099,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 f5c426b

Please sign in to comment.