Skip to content

Commit 9dc31c5

Browse files
committed
fix(uiSref): Ensure URL once param checks pass
Fixes #2091
1 parent 9dd9aef commit 9dc31c5

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/stateDirectives.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -120,21 +120,18 @@ function $StateRefDirective($state, $timeout) {
120120
require: ['?^uiSrefActive', '?^uiSrefActiveEq'],
121121
link: function(scope, element, attrs, uiSrefActive) {
122122
var ref = parseStateRef(attrs.uiSref, $state.current.name);
123-
var def = { state: ref.state, href: null, nav: true, params: null };
123+
var def = { state: ref.state, href: null, params: null };
124124
var type = getTypeInfo(element);
125125
var active = uiSrefActive[1] || uiSrefActive[0];
126126

127127
def.options = extend(defaultOpts(element, $state), attrs.uiSrefOpts ? scope.$eval(attrs.uiSrefOpts) : {});
128128

129129
var update = function(val) {
130130
if (val) def.params = angular.copy(val);
131-
if (!def.nav) return;
132-
133131
def.href = $state.href(ref.state, def.params, def.options);
134-
def.nav = (def.href !== null);
135132

136133
if (active) active.$$addStateInfo(ref.state, def.params);
137-
if (def.nav) attrs.$set(type.attr, def.href);
134+
if (def.href !== null) attrs.$set(type.attr, def.href);
138135
};
139136

140137
if (ref.paramExpr) {

test/stateDirectivesSpec.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('uiStateRef', function() {
1212
url: '/contacts',
1313
template: '<a ui-sref=".item({ id: 5 })" class="item">Person</a> <ui-view></ui-view>'
1414
}).state('contacts.item', {
15-
url: '/:id',
15+
url: '/{id:int}',
1616
template: '<a ui-sref=".detail" class="item-detail">Detail</a> | <a ui-sref="^" class="item-parent">Parent</a> | <ui-view></ui-view>'
1717
}).state('contacts.item.detail', {
1818
template: '<div class="title">Detail</div> | <a ui-sref="^" class="item-parent2">Item</a>'
@@ -130,7 +130,7 @@ describe('uiStateRef', function() {
130130
$q.flush();
131131

132132
expect($state.current.name).toEqual('contacts.item.detail');
133-
expect($stateParams).toEqual({ id: "5" });
133+
expect($stateParams).toEqual({ id: 5 });
134134
}));
135135

136136
it('should transition when given a click that contains no data (fake-click)', inject(function($state, $stateParams, $q) {
@@ -147,7 +147,7 @@ describe('uiStateRef', function() {
147147
$q.flush();
148148

149149
expect($state.current.name).toEqual('contacts.item.detail');
150-
expect($stateParams).toEqual({ id: "5" });
150+
expect($stateParams).toEqual({ id: 5 });
151151
}));
152152

153153
it('should not transition states when ctrl-clicked', inject(function($state, $stateParams, $q) {
@@ -393,7 +393,7 @@ describe('uiStateRef', function() {
393393
$q.flush();
394394

395395
expect($state.$current.name).toBe("contacts.item.detail");
396-
expect($state.params).toEqual({ id: "5" });
396+
expect($state.params).toEqual({ id: 5 });
397397
}));
398398

399399
it('should resolve states from parent uiView', inject(function ($state, $stateParams, $q, $timeout) {

0 commit comments

Comments
 (0)