1

I am taking help of the https://github.com/thinkadoo/Projects application. I have built a similar app with the help of this one. My application is using d3 charts instead of the one this uses. My app initializes the routers as

  var patientStatus = new PatientStatus('#application', {'credentials':Credentials,'secret':Secret});

Now if i want to implement Router then what changes should be done? Here is my JSFiddle with both implementations. The first one is working. But the later part where in I am initializing the Router doesnt seem to work. http://jsfiddle.net/sweety1112/YMAjm/

Can some one help me.

ramblinjan
  • 6,578
  • 3
  • 30
  • 38
Shraddha Shravagi
  • 1,096
  • 1
  • 9
  • 22

1 Answers1

3

Here is an updated Fiddle that shows how routing works:

  var Router = can.Control({
    defaults: {}
  }, {
    init: function() {
      // this.element.html(can.view('#index', {}));
    },

    ':type/:id route': function(data) {
        console.log('Type:', data.type);
        console.log('Id:', data.id);
    }
  });

  can.route.ready(false);
  new Router('#content');
  can.route.ready(true);

Basically, what you do is initialize your named placeholders and tell the controller that this should be handled by the route processor. Now if you go to a URL like #!test/23 the data of the handler will contain a type and id property.

Daff
  • 43,734
  • 9
  • 106
  • 120
  • Hey Daff thanks a lot. It is working. I implemented your as per your suggestion but now my problem is only the first controller is invoked and the rest routes direct yto the same one. I have many routes like Projects, Status, Detail etc... After running the code mentioned in the fiddle every link shows the projects view. Here is the jsfiddle: http://jsfiddle.net/sweety1112/YMAjm/1/ . Is there any mistake in my code? – Shraddha Shravagi Apr 03 '13 at 06:40
  • My URL is as follows 1.MyProjectHub/index.html#!projects, 2./MyProjectHub/index.html#!status, 3./MyProjectHub/index.html#!detail – Shraddha Shravagi Apr 03 '13 at 06:52
  • You don't need the `:`. That indicates a variable. If you want to match the actual rout, just write it like `projects route` which will exactly match `#!projects`. – Daff Apr 03 '13 at 16:47