Recommended Ember locationType for URLs in emails

Hi all,

What locationType do you suggest using in emails you send to users?

For example, say there’s a “click to login” link in the email. The login page is a template within an Ember app. This Ember app also serves the root path.

The login URL used in the email could be one of:

  • http://example.tld/#/login (locationType: hash)
  • http://example.tld/login/#/login (locationType: history+hash) Covers both scenarios?
  • http://example.tld/login (locationType: history) In browsers that don’t support the History API (e.g. Android 4.0 stock, non-Chrome browser), I believe this will show the index page of the Ember app, not the login page.

Thanks,

Eliot

I think this question does not relate directly to Ember. Read about REST APIs. This one for example: Best Practices for Designing a Pragmatic RESTful API | Vinay Sahni

In the past, I’ve used http://example.tld/login and added a “downgrade redirect” initializer:

// app/initializers/no-history-api.js

// IE doesn't have window.location.origin
function origin(loc) {
  if (loc.origin) { return loc.origin; }

  var result = `${loc.protocol}//${loc.hostname}`;
  if (loc.port !== '') { result += `:${loc.port}` }
  return result;
}

export default {
  name: 'no-history-api',

  initialize: function() {
    if (window.history) { return; }
    if (window.location.hash !== "") { return; }

    const hashified = origin(window.location) + '#' + window.location.pathname;
    window.location.replace(hashified);
  }
};

It does mean that older browsers will “double-load” the app when navigating from email links. You can sometimes avoid that with User-Agent detection on the server, but it’s imperfect at best, especially since not all browsers send the hash fragment to the server.