Prototype
Prototype

Reputation: 276

How to redirect to Backbone router inside some other function

quick question. I have router which redirects to different parts of the application. One of them is for example game, one is menu etc.

I now want a simple function in javascript that redirects to #game or #menu for example. I know I could use Model with .set function but would that still work the same way?

This is the file where I want to call this redirection:

var Controls = BaseView.extend({
    id: "controls",
    template: require('./controls.tpl'),
    events: {
      'click #game': 'gotoGame',
      'click #menu': 'gotoMenu'
    },

    gotoGame: function() {
        //Redirect to #game
    }
});

And router is inside other file game_router like this:

var Router = BackboneRouteControl.extend({
    routes: {
        'menu': 'menu#index',
        'game': 'game#show'
    }
})

So how can I redirect just to "someaddress"/#game inside one function?

Upvotes: 0

Views: 456

Answers (1)

Akos K
Akos K

Reputation: 7133

Use Router.navigate. In your case it should be something like this:

routerInstance.navigate("game", {trigger: true});

http://backbonejs.org/#Router-navigate

Upvotes: 1

Related Questions