开发者

stop backbone.js default route from firing

I have the following backbone.js controller:

App.Controllers.PlanMembers = Backbone.Controller.extend({
    routes: {
        "message/:messageType": "sendMessage",
        "": "index"
    },

    sendMessage: function (messageType) {
        alert(messageType);
    },

    index: function () {
        alert('should not get here');
    }
});

I want the index to action to be executed when the page loads for the first time which it does, I also have another route which is sent to the sendMessage action and requests are routed fine from links like the one below:

<a class="sms" href="#message/sms" ><img src="/img/buttons/transmit_blue.gif" /></a>

The problem is that after it executes the sendMessage action, it then goes onto fire the index action again开发者_运维技巧 which is not what I require.

Can anyone tell me how to ensure that only the sendMessage Route is fired?


It turns out this is a known issue

This fixed the problem.

I honestly thought I was going insane!


The code that you have added works for me, but I don't know if there is something else in your code that could be causing this. Are you perhaps routing to this action from a view based upon the receipt of a DOM event? If so, the absence of a preventDefault statement can sometimes cause this sort of double-rendering (routing) behavior. So perhaps add some additional context/detail to your question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜