I am using Backbone router with pushState:true to process the URLs of my site. Sample URLs:
Problem . When the user goes to http://domain.com/John/ , the expected photos function is executed. However, when a user navigates to http://domain.com/John without a trailing slash, nothing happens; I assume that the backslash defined in root prevented this.
router
var AppRouter = Backbone.Router.extend({ routes: { '': 'photos', 'photos': 'photos' }, viewing_username: $('#viewing_username').val(), // eg: 'John' photos: function() { console.log('photos'); } }); var app = new AppRouter(); Backbone.history.start({ pushState: true, root: '/' + app.viewing_username + '/' });
JQuery
$('a[data-toggle="tab"]').on('click', function(e) { app.navigate(e.target.getAttribute('href'), true); });
Second attempt
Problem :: This time I removed the backslash in root and http://domain.com/John now starts the route. The problem this time occurs when the user is at http://domain.com/John (which, as it seems to me, is viewed by the browser as a page with the name John ), so when the link is clicked (with the data-toggle="tab" attribute) URL changed to http://domain.com/Johnphotos without sharing / .
How do I solve this problem?
source share