Skip to content
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

Hash and view is not sync when pressing on back button #2723

Closed
samithaf opened this issue May 1, 2016 · 2 comments
Closed

Hash and view is not sync when pressing on back button #2723

samithaf opened this issue May 1, 2016 · 2 comments

Comments

@samithaf
Copy link

samithaf commented May 1, 2016

Hi guys,
I have came across this issue while trying to create a auth interceptor. Here is the use case.
Flow:

  1. User navigate to a screen which user does not have rights to view (Assume state1).
  2. $transitions.onBefore hook detect the navigation and send the user back to the error page
  3. User click the browser back button.

Expected behaviour:
User should not be able to navigate to the state 1
URL should not update to state 1 url.

What really happens:
User cannot navigate to state 1
URL has been update to state 1 url.

Here is a small App which replicate the issue. Please see the console log which output the current Hash
Example

@christopherthielen
Copy link
Contributor

If we enable transition trace .run($trace => $trace.enable(1)) we see this

Transition #0 Digest #2: Started  -> "Transition#0( ''{} -> 'app.state1'{} )"
VM1499 script.js:2 App Hash is  #/app/state1
VM1497 angular-ui-router.js:1665 Transition #1 Digest #4: Started  -> "Transition#1( ''{} -> 'error'{} )"
VM1497 angular-ui-router.js:1737 Transition #1 Digest #4: <- Success  "Transition#1( ''{} -> 'error'{} )", final state: error
VM1497 angular-ui-router.js:1730 Transition #0 Digest #4: <- Rejected "Transition#0( ''{} -> 'app.state1'{} )", reason: TransitionRejection(type: 2, message: The transition has been superseded by a different transition (see detail)., detail: Transition#1( ''{} -> 'error'{} ))
VM1499 script.js:2 App Hash is  #/error
VM1499 script.js:27 user pressing the back button
VM1497 angular-ui-router.js:1665 Transition #2 Digest #8: Started  -> "Transition#2( 'error'{} -> 'app.state1'{} )"
VM1499 script.js:2 App Hash is  #/app/state1
VM1497 angular-ui-router.js:1672 Transition #3 Digest #9: Ignored  <> "Transition#3( 'error'{} -> 'error'{} )"
VM1497 angular-ui-router.js:1730 Transition #2 Digest #9: <- Rejected "Transition#2( 'error'{} -> 'app.state1'{} )", reason: TransitionRejection(type: 2, message: The transition has been superseded by a different transition (see detail)., detail: Transition#3( 'error'{} -> 'error'{} ))

So here's what I think is happening:

  1. Navigate to state 1 (Transition Design #1)
  2. onBefore() Navigates to error (Transition Looking for Team Members! #2)
  3. Transition Design #1 cancelled because it was superseded
  4. Transition Looking for Team Members! #2 completed to error
  5. Back button pressed, url changes to /state/1
  6. onBefore() Navigate to error (Transition Pseudo Code #3)
  7. Transition Pseudo Code #3 ignored because we're already on error
  8. The URL reseting logic doesn't do anything when the transition is "ignored"

@xr
Copy link

xr commented Sep 7, 2016

hi, beta-1.0 still have this problems when change state inside $transition onStart hook function, any solutions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants