Skip to content

Commit

Permalink
Never include trailing slash on the root.
Browse files Browse the repository at this point in the history
  • Loading branch information
braddunbar committed Jul 5, 2013
1 parent 0a662d6 commit 151bd73
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
6 changes: 3 additions & 3 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1473,14 +1473,14 @@
if (!History.started) return false;
if (!options || options === true) options = {trigger: !!options};

var trailing = fragment === '/';
fragment = this.getFragment(fragment || '');

if (this.fragment === fragment) return;
this.fragment = fragment;

var url = this.root + fragment;
if (!trailing && fragment === '') url = url.slice(0, -1);

// Don't include a trailing slash on the root.
if (fragment === '') url = url.slice(0, -1);

// If pushState is available, we use it to set the fragment as a real URL.
if (this._hasPushState) {
Expand Down
17 changes: 1 addition & 16 deletions test/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ $(document).ready(function() {
Backbone.history.checkUrl();
});

test('Trailing slash on root.', 1, function() {
test('#2656 - No trailing slash on root.', 1, function() {
Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {
location: location,
Expand All @@ -671,19 +671,4 @@ $(document).ready(function() {
Backbone.history.navigate('');
});

test('Trailing slash on root.', 1, function() {
Backbone.history.stop();
Backbone.history = _.extend(new Backbone.History, {
location: location,
history: {
pushState: function(state, title, url){
strictEqual(url, '/root/');
}
}
});
location.replace('http://example.com/root/path');
Backbone.history.start({pushState: true, root: 'root'});
Backbone.history.navigate('/');
});

});

1 comment on commit 151bd73

@ellatrix
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not? My root ends with a trailing slash. If I navigate( '/' ) Backbone shouldn't remove my trailing slash.

Please # to comment.