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

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

$
0
0

I'm thinking that there are 4 types of "unroutables":

  1. external host/port
  2. external path (outside app root)
  3. ignored route (can.route.ignore)
  4. unrouted path
What do you guys think of this as an API?:

  1. /*
  2.     @param {Event} event
  3.     @param {Object} data Contains route information.
  4.     @param {URLUtils} url
  5. */
  6. can.route.bind("unroutable", function(event, data, url)
  7. {
  8.     var loc = window.location;
  9.     
  10.     if (url.host != loc.host || url.port != loc.port || url.protocol != loc.protocol)
  11.     {
  12.         // different host/port
  13.     }
  14.     else if (url.pathname.indexOf(can.route.bindings.pushstate.root) != 0)
  15.     {
  16.         // external path (outside app root)
  17.     }
  18.     else if (data.route === false)
  19.     {
  20.         // ignored route
  21.     }
  22.     else if ( can.isEmptyObject(data.route) )
  23.     {
  24.         // unrouted (simulated 404?)
  25.     }
  26.     
  27.     // stops links from refreshing the page (for whatever reason)
  28.     if (event.currentTarget.tagName == "A")
  29.     {
  30.         event.preventDefault();
  31.     }
  32. });


Viewing all articles
Browse latest Browse all 3491

Trending Articles