So I need to remove a router in backbone.js to prevent it’s routes from occuring. I’ve tried myRouter.off() and myRouter.remove() without any luck.
What can I do instead?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There’s no officially supported way to do this (that I know of). If you want to disable any router, you can use
Backbone.history.stop();, which is undocumented, but shows up in the source code with this comment:Otherwise, you’d have to code some passthrough condition in your router’s route handlers if the state of the router is “disabled” or something like that. Or iterate on the undocumented Backbone.history.handlers (the internal array containing the .route – as a regexp – and .callback) and remove the routes related to this specific router.
Obviously, being undocumented and all, this is subject to change in future releases of Backbone.