1

I'm working with Backbone.js using Backbone Boilerplate and what I'm looking for is a way to pass an id of a dynamic route into the view. So the view can download stuff (via xhr) depends on the string in that id.

Static route usually looks like this:

router.on('route:some-route', function () {
  require(['views/some-view'], function (ViewPage) {
    var viewPage = Vm.create(appView, 'viewPage', ViewPage);
    viewPage.render();
  });
});

For dynamic one you simply need to include the route parameter as an argument:

router.on('route:some-route', function (id) {
  ......
});

So I need a solution where the route parameter can be passed into the view. What is the most efficient way to do that?

Roman Liutikov
  • 1,338
  • 10
  • 17

2 Answers2

1

Ok, I figured out. It's simple. You just need to pass the id to view render.

viewPage.render(id);
Roman Liutikov
  • 1,338
  • 10
  • 17
  • I was wondering, how do you do something with the id? I am trying to load a view with different content based on the id, so I want to be able to say to load content at position[id] in the array... any help would be great thanks! – Lion789 Oct 18 '13 at 03:56
0

Have a look at my backbone boilerplate https://github.com/hbarroso/backbone-boilerplate

I think this exactly what you need with dynamic routing

Henrique B.
  • 450
  • 3
  • 9
  • Using your boilerplate, how does one pass parameters to modules. I have a module that is routed as follows: `router.route("v2/site/:id", "main", function () { console.log("Site route trigger"); this.loadModule("bundles/project/main"); });` How do I reference that "id" parameter from within main.js? – DavidH Apr 26 '13 at 20:21