Fixed Backbone.History.navigate and Backbone.History.start so any url changes include a slash between the root and route fragment when using pushState

This commit is contained in:
Jamie Rolfs
2012-07-26 09:45:57 -06:00
parent 8b23c013b0
commit 86cffe9bc2
2 changed files with 37 additions and 2 deletions

View File

@@ -318,4 +318,34 @@ $(document).ready(function() {
strictEqual(Backbone.history.fragment, 'x');
});
test("Router: insert slash before fragment when root fragment has no trailing slash", 2, function() {
Backbone.history.stop();
location.replace('http://example.com/root');
Backbone.history = new Backbone.History({
location: location,
history: {
pushState: function(state, title, url) {
strictEqual(url, '/root/fragment');
},
replaceState: function(state, title, url) {
strictEqual(url, 'http://example.com/root/fragment');
}
}
});
Backbone.history.start({
pushState: true,
root: '/root',
hashChange: false
});
Backbone.history.navigate('fragment');
Backbone.history.stop();
location.replace('http://example.com/root#fragment');
location.protocol = 'http:';
location.host = 'example.com';
Backbone.history.start({
root: '/root'
});
});
});