Skip to content

Commit f64203c

Browse files
committed
Correct behaviour for trailing slashes
fixes #2741 - Extend HistoryLocation - Add trailing slash to path
1 parent 169a984 commit f64203c

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

core/client/app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Resolver from 'ember/resolver';
22
import initFixtures from 'ghost/fixtures/init';
33
import {currentUser, injectCurrentUser} from 'ghost/initializers/current-user';
44
import {registerNotifications, injectNotifications} from 'ghost/initializers/notifications';
5+
import registerTrailingLocationHistory from 'ghost/initializers/trailing-history';
56
import 'ghost/utils/link-view';
67
import 'ghost/utils/text-field';
78

@@ -24,5 +25,6 @@ App.initializer(currentUser);
2425
App.initializer(injectCurrentUser);
2526
App.initializer(registerNotifications);
2627
App.initializer(injectNotifications);
28+
App.initializer(registerTrailingLocationHistory);
2729

2830
export default App;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*global Ember */
2+
3+
var trailingHistory = Ember.HistoryLocation.extend({
4+
setURL: function (path) {
5+
var state = this.getState();
6+
path = this.formatURL(path);
7+
path = path.replace(/\/?$/, '/');
8+
9+
if (state && state.path !== path) {
10+
this.pushState(path);
11+
}
12+
}
13+
});
14+
15+
var registerTrailingLocationHistory = {
16+
name: 'registerTrailingLocationHistory',
17+
18+
initialize: function (container, application) {
19+
application.register('location:trailing-history', trailingHistory);
20+
}
21+
};
22+
23+
export default registerTrailingLocationHistory;

core/client/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
var Router = Ember.Router.extend();
55

66
Router.reopen({
7-
location: 'history', // use HTML5 History API instead of hash-tag based URLs
7+
location: 'trailing-history', // use HTML5 History API instead of hash-tag based URLs
88
rootURL: '/ghost/ember/' // admin interface lives under sub-directory /ghost
99
});
1010

0 commit comments

Comments
 (0)