2011.05.19

Crossroads.js: JavaScript Routes

The project isn’t that new anymore and was already featured on a couple places but I think I should also create a post just in case someone missed it and also to register the release.

Crossroads is basically a routing system used to map strings to functions (usually URL fragments), it acts similar to a pub/sub (event listener) but uses Regular Expressions and dynamic string patterns to identify listeners. The main feature is the robust and flexible string validation/match/parsing system.

The greatest advantage of Crossroads when compared to other similar libraries is that it is not directly tied to server requests (in case you are using it on the server-side) or to the window.location (if you are on the browser). Another important advantages are the flexibility and the support for advanced use cases, provided by different kinds of validation rules and multiple listeners to each route. – It gives you flexibility to do any kind of action you want and doesn’t do anything you don’t ask it to do.

Check the project page and examples to know more about it. It can be specially helpful for large websites and single page apps – as I mentioned on my previous post.

I hope you enjoy, contributors are welcome.


Comments

Thanks for the work on crossroads.js. I agree with you 100% on "The greatest advantage of Crossroads when compared to other similar libraries is that it is not directly tied to server requests (in case you are using it on the server-side) or to the window.location (if you are on the browser)". That's why i pick crossroads over there. I also added an extension to support history in the browser if someone needs that aspect. Can read more about the extension at http://emmanuelbuah.wordpress.com/2011/07/26/routing-with-crossroads-js-browser-historyfrom-backbone-js/ which has link to gist for download. Again, thanks for your work.

I've released Hasher last week to provide an easy and crossbrowser way of listening to the hashchange event. Check it out: http://blog.millermedeiros.com/2011/08/hasher-deep-linking-for-rich-media-applications/

Perhaps it was me just being silly but I really couldn't figure how to get crossroads to respond to URL changes. I understand now that this is the job of hasher. I think it might help first time users if you explained this a little bit further using a full http://... web address example. I had initally thought crossroads handled all the routings (including URL changes) and hasher simply wrote to the history if you called the route using crossroads rather than via the location bar.

Thanks for the crossroads and hasher (and signals) they're great because they just work!

[...] 不是什么项目都需要这个,不过Flash深链接增强可用性很多使用。Miller Mederios的Crossroads胜任。还有别的选择,不过我还是觉得这个易用。 [...]

[...] Routing, aka deep linking. Try Crossroads [...]

Leave a Comment

Please post only comments that will add value to the content of this page. Please read the about page to understand the objective of this blog and the way I think about it. Thanks.

Comments are parsed as Markdown and you can use basic HTML tags (a, blockquote, cite, code, del, em, strong) but some code may be striped if not escaped (specially PHP and HTML tags that aren't on the list). Line and paragraph breaks automatic. Code blocks should be indented with 4 spaces.