Correct behaviour for trailing slashes

fixes #2741
- Extend HistoryLocation
- Add trailing slash to path
This commit is contained in:
Fabian Becker 2014-05-14 01:52:31 +00:00
parent 169a984372
commit f64203cdf7
3 changed files with 26 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import Resolver from 'ember/resolver';
import initFixtures from 'ghost/fixtures/init';
import {currentUser, injectCurrentUser} from 'ghost/initializers/current-user';
import {registerNotifications, injectNotifications} from 'ghost/initializers/notifications';
import registerTrailingLocationHistory from 'ghost/initializers/trailing-history';
import 'ghost/utils/link-view';
import 'ghost/utils/text-field';
@ -24,5 +25,6 @@ App.initializer(currentUser);
App.initializer(injectCurrentUser);
App.initializer(registerNotifications);
App.initializer(injectNotifications);
App.initializer(registerTrailingLocationHistory);
export default App;

View File

@ -0,0 +1,23 @@
/*global Ember */
var trailingHistory = Ember.HistoryLocation.extend({
setURL: function (path) {
var state = this.getState();
path = this.formatURL(path);
path = path.replace(/\/?$/, '/');
if (state && state.path !== path) {
this.pushState(path);
}
}
});
var registerTrailingLocationHistory = {
name: 'registerTrailingLocationHistory',
initialize: function (container, application) {
application.register('location:trailing-history', trailingHistory);
}
};
export default registerTrailingLocationHistory;

View File

@ -4,7 +4,7 @@
var Router = Ember.Router.extend();
Router.reopen({
location: 'history', // use HTML5 History API instead of hash-tag based URLs
location: 'trailing-history', // use HTML5 History API instead of hash-tag based URLs
rootURL: '/ghost/ember/' // admin interface lives under sub-directory /ghost
});