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

Re : how to catch 404s with can.route.pushstate

$
0
0
Doh. It shouldn't require nullrouter: the above snippet is based on the last commit before we gave up and tried the nullrouter idea. I think we were using 2.0.1 or 2.0.2 at the time -- it's very possible we had some local modifications to can.route, but I don't see anything like that in our git log.

Looking back through, the exact line we used was if (!can.route.attr().hasOwnProperty('route')) { ... -- this might be at fault, since the code I posted will incorrectly reject the falsey "" route in your original post.

--

I just tried this with the normal pushstate plugin, and got the expected result. Here's what I'm getting, currently using 2.0.3:
  1. // when the app is first loading:
  2. // (I'm stealing can/route/pushstate, and not touching or stealing nullrouter at all)
  3. can.route.bindings.pushstate.root = '/demo/';
  4. can.route('account/:acid', { pageName: 'account-detail', workspaceName: 'account-overview' });

  5. // inside my top-level app-loading control, AppLoader.init():
  6. can.route.ready();
  7. console.log('initial route = ', can.route.attr('route'), can.route.attr());
I get the following output:
  1. initial route = account/:acid
  2. acid: "123"
  3. pageName: "account-detail"
  4. route: "account/:acid"
  5. workspaceName: "account-overview"
  6.  }

The extra params (pageName and workspaceName, and the "/demo/" root) are all things we have in our 'real' app. I suspect (hope?) that don't affect anything here.


Viewing all articles
Browse latest Browse all 3491

Trending Articles