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

URL doesn't change after transition hooks is called. #2455

Closed
tankiJong opened this issue Jan 12, 2016 · 5 comments
Closed

URL doesn't change after transition hooks is called. #2455

tankiJong opened this issue Jan 12, 2016 · 5 comments
Assignees
Milestone

Comments

@tankiJong
Copy link

I found this problem in my own work. I will explain this bug by the the sample.

The example is quite nice but i noticed that the URL didn't correctly changed. You may saw this bug by the following steps:

  1. run the app (now you're still unauthenticated)
  2. for convenience, you may directly visit this route. http://localhost:xxxx/new-state-vis/#/mymessages/inbox/ (change xxxx to your port)

(chris edit: http://christopherthielen.github.io/new-state-vis/#/mymessages/inbox/5648b50cc586cac4aed6836f )

and the bug appears. you will find the page has already jump to the login page but the url kept unchanged.

PS. In this example, onBefore hook is applied.

@christopherthielen christopherthielen self-assigned this Jan 15, 2016
@christopherthielen
Copy link
Contributor

Thanks for the bug report.

@christopherthielen
Copy link
Contributor

Looks like "resetting the url when transition is cancelled", i.e., $urlRouter.update() was something only done in the deprecated state events. We'll have to migrate that behavior to the TransitionManager, I believe.

0.2.17: e00aa69

@christopherthielen
Copy link
Contributor

minimal reproduction: http://plnkr.co/edit/7ZJEeUkAdEfiOFhvJiWH?p=preview

@christopherthielen
Copy link
Contributor

@tankiJong were you doing a redirect in your onBefore hook, or something else?

The scenario in the plunker I posted one post up happens for the following reason:

The original transition occurs when ui-router checks the URL and transitions to the proper state. When we sync the state to the URL like that, we use location: false in the transition options. That option is used so the URL doesn't get re-pushed after the transition is complete. When the redirect occurs, we re-use the previous transition's options, (including location: false).

If your hook is doing a redirect, you can add { location: true} to the options, i.e., $state.target('foo', undefined, { location: true }) as a workaround.


I'm thinking about this and wondering what the correct behavior should be. Should we propagate the redirected transition's options or not...

I'm also wondering if we need location: false for transitions that happen when when synchronizing from the url

@tankiJong
Copy link
Author

@christopherthielen
Regardless the code logic, I think the url should always maps the state name and be checked up at some key point.

In addition, is there any way to change the URL without reload the controller?

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

2 participants