Skip to content

Commit

Permalink
fix(uiSref): nagivate to state when url is ""
Browse files Browse the repository at this point in the history
fix($state.href): generate href for state with url: ""

Made resolve values ignore any keys that we're actively trying to resolve, when they also exist in some parent state.
Made ui-sref ignore a single preventDefault that comes from the <a> directive when there is no href (and the ui-sref is on an <a>)
  • Loading branch information
christopherthielen committed Sep 12, 2014
1 parent 0a9aa0c commit 2588c24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {

var nav = (state && options.lossy) ? state.navigable : state;

if (!nav || !nav.url) {
if (!nav || nav.url === undefined || nav.url === null) {
return null;
}
return $urlRouter.href(nav.url, filterByKeys(objectKeys(state.params), params || {}), {
Expand Down
8 changes: 6 additions & 2 deletions src/stateDirectives.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function $StateRefDirective($state, $timeout) {
link: function(scope, element, attrs, uiSrefActive) {
var ref = parseStateRef(attrs.uiSref, $state.current.name);
var params = null, url = null, base = stateContext(element) || $state.$current;
var newHref = null, isAnchor = element.prop("tagName") === "A";
var isForm = element[0].nodeName === "FORM";
var attr = isForm ? "action" : "href", nav = true;

Expand All @@ -102,7 +103,7 @@ function $StateRefDirective($state, $timeout) {
if (newVal) params = newVal;
if (!nav) return;

var newHref = $state.href(ref.state, params, options);
newHref = $state.href(ref.state, params, options);

var activeDirective = uiSrefActive[1] || uiSrefActive[0];
if (activeDirective) {
Expand Down Expand Up @@ -134,8 +135,11 @@ function $StateRefDirective($state, $timeout) {
});
e.preventDefault();

// if the state has no URL, ignore one preventDefault from the <a> directive.
var ignorePreventDefaultCount = isAnchor && !newHref ? 1: 0;
e.preventDefault = function() {
$timeout.cancel(transition);
if (ignorePreventDefaultCount-- <= 0)
$timeout.cancel(transition);
};
}
});
Expand Down

0 comments on commit 2588c24

Please sign in to comment.