Reputation: 760
in a very simple backbone app, I tried manipulating routes, I have them working, but I'm just wondering why the links to the homepage actually reload the page, when no other routes do reload.
Here's my router:
App.Router = Backbone.Router.extend({
routes: {
'': 'index',
'trips': 'trips',
'trips/new': 'newTrip',
'trips/:id': 'showTrip'
},
index: function(){
App.trips = new App.Collections.Trips ;
App.trips.fetch().then(function(){
new App.Views.App({ collection: App.trips });
});
},
trips: function(){
console.log('All trips') ;
},
newTrip: function(){
console.log('new trip') ;
var new_trip = new App.Views.Trip.New ;
$('#content').empty().append(new_trip.el) ;
},
showTrip: function(id){
console.log('trips id:' + id) ;
}
});
Upvotes: 1
Views: 1547
Reputation: 5079
If you use a Backbone router or a link you must be aware of the fact that every route is handled with the #
as long as you have not enabled pushstate (on your browser and server).
So if you need to set a link to home use #
like <a class="brand" href="#/">Home</a>
otherwise the link is handled as a native url
Upvotes: 2