Permalink
Browse files

HistoryLocation appends paths to router rootURL

  • Loading branch information...
digitaltoad committed Jul 11, 2012
1 parent e616ab2 commit d77a0cf69de505104290874fedc1224b8a77b53c
@@ -10,6 +10,11 @@ Ember.HistoryLocation = Ember.Object.extend({
set(this, '_initialURL', get(this, 'location').pathname);
},
/**
Will be pre-pended to path upon state change
*/
rootURL: '',
/**
@private
@@ -35,7 +40,7 @@ Ember.HistoryLocation = Ember.Object.extend({
var state = window.history.state,
initialURL = get(this, '_initialURL');
if (path === "") { path = '/'; }
path = this.formatPath(path);
if ((initialURL && initialURL !== path) || (state && state.path !== path)) {
set(this, '_initialURL', null);
@@ -57,6 +62,21 @@ Ember.HistoryLocation = Ember.Object.extend({
});
},
/**
@private
returns the given path appended to rootURL
*/
formatPath: function(path) {
var rootURL = get(this, 'rootURL');
if (rootURL.charAt(-1) === '/') {
rootURL = rootURL.substr(-1);
}
return rootURL + path;
},
/**
@private
@@ -149,3 +149,16 @@ test("doesn't push a state if path has not changed", function() {
locationObject.setURL(window.location.pathname);
});
test("it prepends rootURL to path", function() {
var setPath;
window.history.pushState = function(data, title, path) {
setPath = path;
};
locationObject.set('rootURL', '/test');
locationObject.setURL("/foo");
equal(setPath, '/test/foo');
});
@@ -378,6 +378,16 @@ Ember.Router = Ember.StateManager.extend(
*/
location: 'hash',
/**
This is only used when a history location is used so that applications that
don't live at the root of the domain can append paths to their root.
@type String
@default ''
*/
rootURL: '',
/**
On router, transitionEvent should be called connectOutlets
@@ -462,9 +472,14 @@ Ember.Router = Ember.StateManager.extend(
init: function() {
this._super();
var location = get(this, 'location');
var location = get(this, 'location'),
rootURL = get(this, 'rootURL');
if ('string' === typeof location) {
set(this, 'location', Ember.Location.create({ implementation: location }));
set(this, 'location', Ember.Location.create({
implementation: location,
rootURL: rootURL
}));
}
},

0 comments on commit d77a0cf

Please sign in to comment.