Ed .
Ed .

Reputation: 6403

Using a normal link in Ember

I've got a normal anchor tag in my HTML but that's wrapped in an action handler (possibly more than one).

Problem: When I click on the link it gets swallowed by one of those actions.

Example template:

<div {{action 'doSomething'}}> 
  ...
  <a href="www.google.com" target="_blank">Google</a>
  ...
</div>

I feel that clicking on an anchor tag with no action should take precedence over parent action handlers but that doesn't seem to be the case.

I've been debugging and see this bit of code in Ember:

ActionHelper.registerAction = function (_ref) {
  ...
  var preventDefault = _ref.preventDefault;
  ...

  actions.push({
    ...
    handler: function (event) {
      ...
      if (preventDefault !== false) {
        event.preventDefault();
      }
      ...
    }
  })
}

When I click on the link it always seems to think that it should preventDefault...

I've tried finding parent actions and adding preventDefault=false but no luck.

Upvotes: 1

Views: 193

Answers (1)

Lo&#239;c Faure-Lacroix
Lo&#239;c Faure-Lacroix

Reputation: 13600

Apparently, you have to call an action in order to do that. What you could do is this:

<a href="newPage.htm" {{action 'emptyAction' preventDefault=false}}>Go</a>

Here's a link with more information on emberjs:

https://guides.emberjs.com/v1.13.0/templates/actions/#toc_allowing-default-browser-action

Upvotes: 1

Related Questions