-
Notifications
You must be signed in to change notification settings - Fork 3k
Browser navigation broken #2192
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
Comments
why are you doing an ajax call in the state change event? |
I'm doing an authentication check. |
No idea what you mean by the results weren't satisfactory |
I used to have a resolve for every single state of the app so that there could be an ajax request performed before entering any step (for authentication checks). The problem is that moving back from a child state to its parent state, wouldn't trigger the authentication resolve of the parent state again. I spent a lot of time on this and I ended up going for the much simpler solution of putting the authentication check in the state transition. It made more sense to me to have it there too. And it's working perfectly now btw, with the workaround I proposed. |
Could this maybe be reopened? |
@nateabele I'm pretty sure I've tried that but I couldn't get access to toState and toParams from the |
Right, you'd need some intermediary service to synchronize the two. |
@FLO-G Did you find a solution? |
I am using 0.2.18, I added event.preventDefault(); and it works now |
Hi, I first mentioned this problem in #1699 (comment)
I have a problem with the browser back button looping.
The following does not break the history API:
The following does:
(obviously, I'm not just setting a timeout for the heck of it, but I'm doing some ajax call)
My fix is the following, in angular-ui-router.js version 0.2.15 line 3231:
The problematic case with this $urlRouter.update call is the following:
When I hit the browser back button, the url is updated by the browser before
$stateChangeStart
is called (as opposed to when there is a normal$state.go
nav).Since
event.preventDefault
was called on the$stateChangeStart
event,$urlRouter.update
is called. In the code below,$location.url()
is not equal tolocation
($location.url()
is the one of the toState andlocation
is the one of the fromState).So
$location.url(location); $location.replace();
are called with the url of the fromState which creates a new browser history entry I think (this explains the loop). I'm using chrome 43.0 btw, but I don't think it's relevant.angular-ui-router version 0.2.15 line 2064:
I suppose there is a good reason for that
$urlRouter.update
call. Maybe we could set some property on the$stateChangeStart
event to let the router know not to make that call.It may not look very clean, but I can't think of another way around.
The text was updated successfully, but these errors were encountered: