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

Route Bindin

$
0
0
Hey Justin/Brian/CanJs Team, It's Josh from BrightRoll, I hope all is well and look forward to seeing you guys again soon!

I'm experiencing an issue where a route binding is matched twice when it isn't expected to be matched(At least unexpected by me).

--We call the following from another area of the app(to be specific a grid row onclick handler):

  1. var routeObj = {
  2. action: "edit"
  3. foo_id: "123"
  4. foo_name: "Test"
  5. ids: "4"
  6. route: "foo/:foo_id/:foo_name/bar/:action"
  7. }
  8. can.route.attr(routeObj, true);

and based on the definition below, I see routeBarEdit fire twice, instead of once which is what I would expect
  1. /* globals uiReady */
  2. steal(
  3.   'can'
  4. ).then(function() {
  5.   'use strict';
  6.   can.Control('Foo.Router', {}, {
  7.    ....
  8.     route: function() {
  9.       can.route.attr({
  10.         route: 'foo/'
  11.       }, true);
  12.     },
  13.     ....
  14.     routeBarEdit: function(route) {
  15.       // I see this called twice
  16.       GlobalNameSpace.Control.changePageController(Foo.Bar.Router, {
  17.         module: 'foo',
  18.         name: route.foo_name || 'Bar'
  19.       });
  20.     },
  21.  
  22.     // Edit Bar
  23.     'foo/:foo_id/:foo_name/bar/:action route': 'routeBarEdit',
  24.     'foo/:foo_id/:foo_name/bar/:action/:ids route': 'routeBarEdit',
  25.     'foo/:foo_id/:foo_name/bar/:action/:ids/ route': 'routeBarEdit'
  26.   });
  27. });
I guess what I'm looking for is the best way to approach this problem.......in Rails the first route matched will be the only one that will fire, but for can routing that is not the case so I figured I would ask about the best practices. I saw a mention in the docs (http://canjs.com/docs/can.route.html) of using a can.Map.delegate to control multiple route calls but I wasn't sure if that was the best way to approach this specific problem.

Thank you in advance for any suggestions/pointers/guidance.

Viewing all articles
Browse latest Browse all 3491

Trending Articles