0

I'm creating my first application that uses the Backbonejs router.

http://backbonejs.org/#Router

I'm curious, is it possible to define a route that will fire for every url segment except one?

In my case, I don't want this callback to fire if the url is http://www.example.com/login, but I do want it to fire for

My router looks like this:

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');
    }
});
mu is too short
  • 426,620
  • 70
  • 833
  • 800
Casey Flynn
  • 13,654
  • 23
  • 103
  • 194
  • 1
    Have you looked at [this](http://stackoverflow.com/questions/10270840/backbone-js-and-regex-routing?rq=1)? – madfriend Jun 21 '12 at 21:41
  • 1
    Haven't you tried this? `routes:{ "login":"login", "*":"landing" }` the difference it makes is routes are called based on precedence of matches. Here if we provide * as first root it will be called for all the routes regardless of login, foo, bar. But we do want `login` right? so we give precedence to login route by pushing it up the definition ladder.Now it works :) go enjoy the hot cut of chocolate – Deeptechtons Jun 22 '12 at 09:44

1 Answers1

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
}
});
Jason
  • 4,079
  • 4
  • 22
  • 32