Skip to content

Commit

Permalink
Fix #2656 - Trailing slash on root.
Browse files Browse the repository at this point in the history
  • Loading branch information
braddunbar committed Jul 5, 2013
1 parent 25f3949 commit 0a662d6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1472,10 +1472,15 @@
navigate: function(fragment, options) {
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);

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

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('');
});

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('/');
});

});

0 comments on commit 0a662d6

Please # to comment.