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

don't capture click events #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

ile
Copy link

@ile ile commented Oct 22, 2014

I think non-capturing would work better than capturing click events?

If I have something like this: <a href="" on-click="doSomething($event)">....</a> and in doSomething I prevent the default, it will be too late because the url is already changed (in History.js).

Also #19

@zmillman
Copy link
Contributor

I was banging my head against a click propagation problem, and this was the problem.

Because the capturing phase occurs before the bubbling phase (https://www.w3.org/TR/DOM-Level-3-Events/#event-flow), any on-click handlers for children of an <a> never get a chance to prevent the tracks listener from updating the history.

I would expect something like this to work:

<index:>
  <a href="/link-to-profile">
    Jared <span on-click="openPreviewPopup($event)">(preview)</span>
  </a>
MyComponent.prototype.openPreviewPopup = function(e) {
 e.preventDefault() // prevent browser history from changing
 // open popup
}

The only workaround I know right now is to remove the href from the <a> tag and replace it with an on-click handler that pushes the intended URL to the history.

@balek
Copy link

balek commented Oct 23, 2018

A little improvement: you can leave href and add data-router-ignore attribute on the <a> tag

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

Successfully merging this pull request may close these issues.

3 participants