Example #1
0
export function getHistoryPath(rootURL, location) {
  var path = getPath(location);
  var hash = getHash(location);
  var query = getQuery(location);
  var rootURLIndex = path.indexOf(rootURL);
  var routeHash, hashParts;

  assert(`Path ${path} does not start with the provided rootURL ${rootURL}`, rootURLIndex === 0);

  // By convention, Ember.js routes using HashLocation are required to start
  // with `#/`. Anything else should NOT be considered a route and should
  // be passed straight through, without transformation.
  if (hash.substr(0, 2) === '#/') {
    // There could be extra hash segments after the route
    hashParts = hash.substr(1).split('#');
    // The first one is always the route url
    routeHash = hashParts.shift();

    // If the path already has a trailing slash, remove the one
    // from the hashed route so we don't double up.
    if (path.slice(-1) === '/') {
      routeHash = routeHash.substr(1);
    }

    // This is the "expected" final order
    path = path + routeHash + query;

    if (hashParts.length) {
      path += `#${hashParts.join('#')}`;
    }
  } else {
    path = path + query + hash;
  }

  return path;
}
Example #2
0
QUnit.test("getQuery() should return location.search as-is", function() {
  expect(1);

  var location = mockBrowserLocation({ search: '?foo=bar' });
  equal(getQuery(location), '?foo=bar');
});