Tuesday, 11 June 2013

Change the hash without calling actions inside Backbone.Router

var Router = Backbone.Router.extend({
    routes: {
        'Registration': 'Registration'    },

    Registration: function() {
        console.log('Registration() called')    }
})
var router = new Router()

Backbone.history.start()

// here the Registration() action is called
router.navigate('Registration', { trigger: true })// => "Registration() called"

// here the Registration() action is not called
router.navigate('Registration')
// => 
Backbone.js applications state is managed by hashes (eg: #resource or #Registration). Everytime the hash changes an action is called inside the Backbone.Router. This is usefull but in some case you may need to change the hash by calling the router. You can achieve it by passing true to navigate() method:

No comments:

Post a Comment