Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Best way to deal with href links in a "{can.route} attribute" setup?

$
0
0
By listening for attribute changes instead of "route" events, regular hrefs are not automatically picked up as routes. What would be the best practice to correct this?

For a link like:
  1. <a href="/app/test/">test</a>
… something like this seems a little excessive:
  1. can.route.bindings.pushstate.root = "/app/";
  2. can.route("", {section:""});
  3. can.route(":section/");
  4. can.route.ready();

  5. "a click": function(element, event)
  6. {
  7. var root = can.route.bindings.pushstate.root;
  8. var href = element.attr("href");
  9. if (href.indexOf(root) >= 0)
  10. {
  11. href = href.substr(root.length);

  12. var params = can.route.deparam(href);
  13. if ( !can.isEmptyObject(params) )
  14. {
  15. // {section:"test", route:":section/"}
  16. console.log(params);
  17. can.route.attr(params);
  18. event.preventDefault();
  19. }
  20. }
  21. }

Viewing all articles
Browse latest Browse all 3491

Trending Articles