millermedeiros / crossroads.js

JavaScript Routes
http://millermedeiros.github.com/crossroads.js/
1.44k stars 156 forks source link

Setting a "default" route? #132

Closed mfromin closed 9 years ago

mfromin commented 9 years ago

Is there a way I can set a route that will be executed when none of my other routes work? I am using route strings and at present I only have a few"

url: '' url: 'about', url: 'contact', url: 'post/{id}',

These solve the ability to route to 4 very specific pages (so far so good). When someone enters a URL that matches no such route I want to send them to the route for the empty string url above. I tried this:

url: '{*}'

...and it works as long as there is no "/" in the URL. As an example it captures this:

http://localhost:63342/koblog/public/index.html#dafdafdfa

...but does not appear to capture this:

http://localhost:63342/koblog/public/index.html#dafdafdfa/1234

This has to be pretty easy I just can't figure out how to do this.

Standa666 commented 9 years ago

try crossroads.bypassed.

https://millermedeiros.github.io/crossroads.js/#crossroads-bypassed

millermedeiros commented 9 years ago

if you need something like a 404 page try a route that matches anything:

// ":rest*:" will match any path
// priority set to `-Infinity` so it's the last route to be checked against
var route404 = crossroads.addRoute(':rest*:', on404, -Infinity);