1

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) ;
}
});
4

1 回答 1

2

如果您使用 Backbone 路由器或链接,您必须知道,#只要您没有启用 pushstate(在您的浏览器和服务器上),每个路由都会被处理。

所以如果你需要设置一个家庭使用的链接#

<a class="brand" href="#/">Home</a>其他方式一样,该链接将作为本机 url 处理

于 2013-03-25T07:15:25.907 回答