Skip to content

[2.0] redirect() not changing hash / abort() equivalent #692

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

Closed
fergaldoyle opened this issue Sep 27, 2016 · 4 comments
Closed

[2.0] redirect() not changing hash / abort() equivalent #692

fergaldoyle opened this issue Sep 27, 2016 · 4 comments

Comments

@fergaldoyle
Copy link

fergaldoyle commented Sep 27, 2016

Example: http://run.plnkr.co/O8drrKqdru329Cf4/#/a
Source: http://plnkr.co/edit/fjHGwqUnUTzq2eDpKVTa?p=preview
Standalone source in case plunker is down: http://pastebin.com/bN2vMGY4

Steps in the above example:

  • Click "Go to B"
  • Click "OK" in the prompt
  • Press back button in the browser
  • Press forward button in the browser
  • Click "Cancel" in the prompt

Result:

  • Component A is correctly shown in the router outlet
  • Page hash is incorrect, still shows #/b

In the previous version of vue-router, using abort() would revert the hash back to the correct path.

On a site note, how do we handle the removal of abort()? redirect() needs you to know the previous path, where as abort() automatically reverted back to the previous path.

@fnlctrl
Copy link
Member

fnlctrl commented Sep 28, 2016

Hi, thanks for filling this issue.

Abort is no longer needed since you can just do nothing inside guard hooks to abort the navigation.
http://plnkr.co/edit/NuiJlxJV4IkhnXOwfgqr

Please read more about navigation guards here:
http://router.vuejs.org/en/advanced/navigation-guards.html

If neither redirect nor next is called, the navigation will be cancelled.

@fnlctrl fnlctrl closed this as completed Sep 28, 2016
@fergaldoyle
Copy link
Author

If neither redirect nor next is called, the navigation will be cancelled.

While navigation is cancelled (i.e. the correct component is displayed in the router outlet), the hash change is not canceled. Previously abort() restored the correct hash / path.

If hash is changed outside of using <router-link />, i.e. browser forward / back or using <a href="#/b" />

  1. browser hash changes (to #/b for example)
  2. beforeEach fires
  3. redirect or next not called
  4. navigation is canceled
  5. hash remains #/b

@fnlctrl
Copy link
Member

fnlctrl commented Sep 28, 2016

If hash is changed outside of using , i.e. browser forward / back or using <a href="#/b" />

  1. browser hash changes (to #/b for example)
  2. beforeEach fires
  3. redirect or next not called
  4. navigation is canceled
  5. hash remains #/b

I see.. It may indeed be a bug. @yyx990803

@fnlctrl fnlctrl reopened this Sep 28, 2016
@yyx990803
Copy link
Member

See https://github.com/vuejs/vue-router/releases/tag/v2.0.0-rc.6

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

No branches or pull requests

3 participants