johno / ember-linkify

Linkify urls in an Ember app with a fancy helper
MIT License
22 stars 30 forks source link

Use default ember transitions for internal links #31

Open cmitz opened 7 years ago

cmitz commented 7 years ago

It would be great not to have a normal page load in "_self" when clicking on a link inside Ember. Currently, using linkify and clicking on a link that directs to a page in the same ember-app, reloads Ember on that page, but that loading time wouldn't be there if a normal transition was used.

Our current solution is always use _blank and override the click event (not my code 😒)

click(ev) {
    // Source: https://github.com/whoward/ember-twitter-clone/commit/93af68d9f504b8b8972487e6c09851d3523a3678
    const href = this.$(ev.target).attr('href');
    if (href) {
      const parser = document.createElement('a');
      parser.href = href;
      if (!(parser.hostname === window.location.hostname || parser.hostname === `www.${window.location.hostname}`)) {
        return;
      }

      ev.preventDefault();
      const router = getOwner(this).lookup('router:main');
      router.transitionTo(parser.pathname);
    }
  }
dnstld commented 5 years ago

Hello, @cmitz. I think we have the same issue =) Take a look at my proposal

https://github.com/johno/ember-linkify/pull/37

cmitz commented 5 years ago

I think your PR is helpful! However, we do not have the same issue. I don't want to specify what target <a>'s should have, but I want the addon to figure it out itself. External links should be "_blank", and internal links should use the router to push a transition...

dnstld commented 5 years ago

Hello @cmitz. Okay, I get it! I'll try to support this addon but I have no much time to implement new features for now. Would you like to implement and open a PR of it? Thanks