简体   繁体   中英

Lightweight alternative to Sammy.js

Is there any small framework that provides hash / url handling similar to sammy.js? I need to bind callbacks to routes - not only for "normal" get requests but also for post/put/delete submissions (both triggered by links / forms or manually from my code).

That's pretty much it and since I'm already using some other frameworks / libraries such as jQuery and knockout.js, I don't want to include a framework like Sammy (that provides too much functionality that I'm not going to use).

I didn't succeed in finding a good solution for this task, so I ended up writing a very tiny component that does this job for me (and nothing else).

It's called Simrou and can be forked at https://github.com/buero-fuer-ideen/Simrou

History.js .

History.js gracefully supports the HTML5 History/State APIs (pushState, replaceState, onPopState) in all browsers. Including continued support for data, titles, replaceState. Supports jQuery, MooTools and Prototype. For HTML5 browsers this means that you can modify the URL directly, without needing to use hashes anymore. For HTML4 browsers it will revert back to using the old onhashchange functionality.

You can use pager.js. Its really cool java script library, using which you can assign your Page title also and it helps you in hash / URL handling.

Visit pagerjs.com

For completeness, thought I'd mention crossroads.js which I've only tried as part of Steve Sander's Yeoman Knockout Generator .

Looks elegant, but I'd appreciate more examples . In particular, I didn't get any search results for " crossroads.js login " or " crossroads.js auth " :(

Crossroads.js is a routing library inspired by URL Route/Dispatch utilities present on frameworks like Rails, Pyramid, Django, CakePHP, CodeIgniter, etc... It parses a string input and decides which action should be executed by matching the string against multiple patterns.

It is a powerful and flexible routing system. If used properly it can reduce code complexity by decoupling objects and also by abstracting navigation paths and server requests.

Another alternative, one that only does routing, and skips templates etc is Davis.js, see http://davisjs.com/ . Only dependency is jQuery.

您可以使用与jQuery 地址插件的深层链接。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM