Project Description
jsRouter is a lightweight URL router written in Javascript. The routing is based on the path after the hash (#) in the URL, thus providing pure client-side navigation for AJAX applications. By imitating ASP.NET MVC's routing, the use pattern is familiar for .NET developers.
Example
Consider a simple scenario: myshop.com wants to implement pure AJAX-navigation between products using jsRouter.
1. Register the routes in your application
function onRootInvoked() { ... }
function onProductsInvoked() { ... }
$.jsRouter.mapRoute('Root', '', onRootInvoked);
$.jsRouter.mapRoute('Products', 'products/{productId}', onProductsInvoked, { productId: 0 });
2. Use normal anchor tags or the navigateTo() method to invoke the routes
<a href="#products">Products</a>
$.jsRouter.navigateTo('Products', { productId: 343434 });
3. The callbacks gets triggered by the matched route
- http://myshop.com/ triggers onRootInvoked
- http://myshop.com/#products will trigger onProductsInvoked with productId set to 0
- http://myshop.com/#products/7724 will trigger onProductsInvoked with arguments containing the productId
Dependencies
This utility is bundled as a jQuery plugin, and jQuery is therefore a required dependency in order for this to work.