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

Router: Clicking on [router-link] directives bypasses native 'onHashChange' events #5013

Closed
matanlurey opened this issue Oct 29, 2015 · 6 comments
Assignees
Milestone

Comments

@matanlurey
Copy link
Contributor

This makes it impossible for third-party code (not aware of Angular) to know when the route has changed. Honestly, I'd prefer for [router-link] to go entirely away or be optional. It's a lot easier and more portable to use plain <a href="..."> and instead have the router deal with understanding those.

For example, [router-link] only supports clicks. Not keyboard.

@btford btford added this to the beta-00 milestone Oct 29, 2015
@btford btford self-assigned this Oct 29, 2015
@btford
Copy link
Contributor

btford commented Oct 29, 2015

There are two parts to this:

  1. Bugs in the behavior of [router-link]
  2. Intercepting link clicks for external 3rd party code.

For 2, I think it makes more sense for your application to implement a directive. But if you don't have the option to compile the 3rd party templates, then intercepting hashchange events makes sense. Again, not sure this makes sense for all Angular apps, you might have to add a listener and add this to routing your self.

We chatted about this in the past, but I'm still thinking through the ideal solution. I'll start work in earnest on this next week.

@wekiel
Copy link

wekiel commented Oct 29, 2015

Hi, Brian, we can't do this via a directive. We need something that works on a global scale (it's not reasonable to track down all required places and add such directive), and also that will notify us when the URL change is done by parts of the app that aren't managed by Angular.

What we need is for the ng2 router to work seamlessly with the onhashchange, just like the ng1 router does right now: https://github.com/angular/route.dart/blob/master/lib/client.dart

@btford
Copy link
Contributor

btford commented Oct 29, 2015

To be clear, yes, there will be the option to intercept this event seamlessly for your use case. It's just that the router also needs to support other cases as well. I wasn't disagreeing, just trying to fully capture the scope of this issue so that other developers with different needs aren't confused.

btford added a commit that referenced this issue Oct 30, 2015
Previously if the URL changed in `HashLocation` mode, the router would not pick up the change.
This adds a listener in `HashLocationStrategy` for `hashchange` events to fix the problem.

Closes #5013
btford added a commit that referenced this issue Oct 30, 2015
Previously if the URL changed in `HashLocation` mode, the router would not pick up the change.
This adds a listener in `HashLocationStrategy` for `hashchange` events to fix the problem.

Closes #5013
@btford btford closed this as completed in 53bddec Oct 30, 2015
@btford
Copy link
Contributor

btford commented Oct 30, 2015

I just landed a change for the third option in master.

@matanlurey
Copy link
Contributor Author

Thank you guys! 👍

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants