MR.ABC
MR.ABC

Reputation: 4862

Backbone Routes / View <= Put all my routes inside Views

Is it reasonable to set the routes inside the view and proceed the events there ? Want to use a logic to pass the action-url from my views and call a function as callback from my AppRoute Class.

I try to avoid strings as event names and i like to have it easy extensible. So can can create a view without change the AppRoutes logic.

AppRoutes.js

Not working code just for demonstration. 

foreach(view in myViewArry)
{
    route(view.url : view.loadAction);
}

View1.js

var id = "#View1";
var url = "View1";
function loadAction(id) { logic... };

View2.js

var id = "#View2";
var url = "View2";
function loadAction(id) { logic... };

Upvotes: 0

Views: 226

Answers (1)

Drejc
Drejc

Reputation: 14286

Backbone has routing build into it, so there is no need to mix your routes inside views.

Take a look at the documentation: http://backbonejs.org/#Router

and this example: http://backbonetutorials.com/what-is-a-router/

Upvotes: 1

Related Questions