简体   繁体   中英

Return to index in backbone.js router

Just wanted to know, what is the proper way of returning to the index in backbone.js? So this is an outline of my code. I have a router, where it creates an instance of a view and passes the current instance of the router.

var AppRouter = Backbone.Router.extend({
    callMasterViefw: function(){
        MasterView.initialize(this);
    },
})

Inside the MasterView , I create an instance of the MasterView and assign the router to it as well. I have a function, called reRouteToIndex , where basically i want to reroute to the index page.

MasterView= Backbone.View.extend({
    render: function(){},
    reRouteToIndex(){
        this.router.navigate("", {trigger: true,replace: true});
    },
});

All this works, but the problem is when I redirect to the index I return to something like www.test.com/index.html/# . Where it is important to note the # at the end. I was wondering if there was a way to route to the original path without the # like this www.test.com/index.html ?

您可以在.navigate()启用pushState (如.navigate({pushState: true, trigger: true})但是您需要配置网络服务器以与mod_rewrite (或等效功能)一起使用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM