-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ui-sref cause redundant state transition #350
Comments
If you look here, you'll notice that |
Hmm, you're right. Still, I have that issue and removing either the |
AFAIK, you can't disable the browser's response to href in html. |
This plunker demonstrates the problem. Interestingly, the issue only happens when the function inside |
When I replace Examining jquery source, I have no idea why propagation has a part in this (again, this issue occurs in both the simple plunker provided as well as my production app). Besides, back to the original question, why should ui-router generates |
Because states don't have to have URLs. |
Maybe the answer is to only do one or the other depending on if a URL is defined. |
Strongly disagree. One of the core concepts of this library is bridging the gap between new-school applications and standard Web conventions, which is what this enables. |
I'm not exactly sure why you think @timkindberg's suggestion defeats that purpose? I don't see how a user can possibly be affected by that change. (Doesn't mean I'm not interested in learning about the root cause & solving it.) |
Sorry, I misread it. I'll try and figure out a solution for this as soon as I can. Probably this weekend. |
I just submitted a PR, please take a look. (Sorry about multiple references in this thread; the PR has only 1 commit however.) |
Please see my comments on the PR. Unfortunately it doesn't really satisfy the requirements. I'll have to add some additional test coverage to |
@buunguyen Thanks for a quick-fix. I'll use yours until offical fix is applied. Since I have some ajax queries on my states' resolve, I don't want to fetch them twice. :) |
@ubenzer you're welcome. I'm also using the |
I also ran into this issue. I couldn't make the event.stopPropagation() hack work in my use case. Here's my workaround:
Calling off will remove the listener. So just call off in foo. Then it doesn't matter if the state change transition starts twice. Obviously, there are lots of instances where this wouldn't work. Looking forward to the real fix in ~ 0.4.0! |
Thanks @buunguyen - I just needed this line: if (isForm || nav) return; Could we get this merged? Double triggering of state is a no-win. |
I ran into similar problem. A state transition is performed twice. It happens when my ui-sref doesn't include all of the state parameters. My intention is to have optional parameter. |
I can confirm that the (as stated by @lubiluk) is with the ui-sref not including all of the state parameters. In my case I was trying to rely on parameters from parent routes already being resolved. |
+1 @lubiluk
I am using the master branch which supposedly should support optional parameters. However, I get the same behavior with |
Still seeing an issue with the empty optional params that @lubiluk mentioned...would be nice to see a fix without a workaround. Not the end of the world as there is a workaround as @kbdaitch brings up, markup ends up looking like |
I got bitten by this even in 0.2.11. |
+1 |
+1 |
+1. Thanks @lubiluk, your observation about missing parameters saved me a lot of time today. |
+1 @lubiluk |
+1 @lubiluk |
Hi @kavarell, query params are optional in v0.2.11, which works without loading the state twice. I recently found a optional parameter syntax somewhere in github for ui-router that uses {}, so something like url: '/my/:param/{optionalParam}', and it works but it also loads the state twice, which is currently a issue for me too, so +1 |
+1 |
+1. Including ui-sref="stateName({ "optionalParam": "" })" fixes it, but we cannot rely on this. |
+1 The tips saved me a lot of time :) |
Try to use $locationChangeStart instead of $stateChangeStart So try calling off as @eupharis, but with locationChangeStart var off = scope.$on('$locationChangeStart', foo); |
Issue observed in angular-ui-router v0.2.18 |
Issue is still observed in angular-ui-router v0.3.2 |
I use angular-ui-router v0.3.1, and register on state change using this code implemented in my controller:
The HTML to trigger the state transition is like: The whole thing is embedded in a Single Page App. I was suspecting the issue to be the state change listener being registered each time the navigation is routing to this page. So I updated the code to unregister in the callback itself:
It now works as expected, as the callback function is only triggered once. |
@patrick-99 : event.preventDefault() wont work in this case |
I noticed that whenever
ui-sref
is used, a state is transitioned to twice. Upon examining the source code, it looks like the issue is caused by the fact that$StateRefDirective
not only generates ahref
but also bindsonclick
event. By removing one of those, the issue is solved.Is this a bug or by design? Given that the built-in
ng-href
only generateshref
, is there a reasonui-sref
has to bind theonclick
event?The text was updated successfully, but these errors were encountered: