0

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?

user229044
  • 232,980
  • 40
  • 330
  • 338
dagda1
  • 26,856
  • 59
  • 237
  • 450
  • The error is happening specifically in IE8, I can see a javascript error with the yellow triangle at the bottom left hand corner of the screen but the error message does not give the game away. Can anyone direct me to where about in the backbone source the would the routing takes place whenever a link is clicked like this? The error appears before the route method is accessed. – dagda1 May 31 '11 at 16:00

2 Answers2

2

It turns out this is a known issue

This fixed the problem.

I honestly thought I was going insane!

Community
  • 1
  • 1
dagda1
  • 26,856
  • 59
  • 237
  • 450
0

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.

Bill Eisenhauer
  • 6,183
  • 2
  • 30
  • 28
  • The anchor in the original post is the way the action is being invoked. From the href="#message/sms". – dagda1 May 31 '11 at 14:30