0

我正在创建我的第一个使用 Backbonejs 路由器的应用程序。

http://backbonejs.org/#Router

我很好奇,是否可以定义一个为除一个之外的每个 url 段触发的路由?

就我而言,如果 url 为 ,我不希望触发此回调http://www.example.com/login,但我确实希望它触发

我的路由器是这样的:

var SuiteRouter = Backbone.Router.extend({
    // ################################ Defined Routes ################################
    routes: {
        "":      "landing",     //Suite primary page, initiates menus and other suite-wide items, initiated everywhere except login
        "login": "login"
    },

    // ########################### Route Callbacks ################################
    landing: function() {
        console.log(arguments);
        console.log('landing');
    },
    login: function() {
        console.log(arguments); //<--- nothing useful, empty array
        console.log('login');
    }
});
4

1 回答 1

0

Yes you can.

var SuiteRouter = Backbone.Router.extend({
    // ################################ Defined Routes ################################
    routes: {
        "":      "landing",     //Suite primary page, initiates menus and other suite-wide items, initiated everywhere except login
        "login": "login"
    },

    // ########################### Route Callbacks ################################
    landing: function() {
        console.log(arguments);
        console.log('landing');
    },
    login: function() {
        console.log(arguments); //<--- nothing useful, empty array
        console.log('login');
    }
});

var router = new Router();
router.on("route", function(route, params) {
console.log(route); //will be called every route change in addition to the appropriate other callbacks.
if(route!=="login") {
//do something
}
});
于 2014-06-04T21:14:45.630 回答