javascript Sammy.js 的轻量级替代品
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9759081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Lightweight alternative to Sammy.js
提问by Niko
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).
有没有提供类似于 sammy.js 的哈希/url 处理的小框架?我需要将回调绑定到路由 - 不仅用于“正常”获取请求,还用于发布/放置/删除提交(均由链接/表单触发或从我的代码手动触发)。
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).
差不多就是这样,因为我已经在使用其他一些框架/库,例如 jQuery 和 Knockout.js,我不想包含像 Sammy 这样的框架(它提供了太多我不会使用的功能) .
回答by Niko
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 Simrouand can be forked at https://github.com/buero-fuer-ideen/Simrou
它叫做Simrou,可以在https://github.com/buero-fuer-ideen/Simrou分叉
回答by Joe Lencioni
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.
History.js 优雅地支持所有浏览器中的 HTML5 历史/状态 API(pushState、replaceState、onPopState)。包括对数据、标题、replaceState 的持续支持。支持 jQuery、MooTools 和 Prototype。对于 HTML5 浏览器,这意味着您可以直接修改 URL,而不再需要使用哈希。对于 HTML4 浏览器,它将恢复使用旧的 onhashchange 功能。
回答by sivanv
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.
您可以使用 pager.js。它非常酷的 Java 脚本库,使用它您还可以分配您的页面标题,它可以帮助您进行哈希/URL 处理。
Visit pagerjs.com
回答by ptim
For completeness, thought I'd mention crossroads.jswhich I've only tried as part of Steve Sander's Yeoman Knockout Generator.
为了完整起见,我想我会提到crossroads.js,我只是作为 Steve Sander 的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 login”或“ 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.
Crossroads.js 是一个路由库,其灵感来自于 Rails、Pyramid、Django、CakePHP、CodeIgniter 等框架上的 URL 路由/调度实用程序......它解析一个字符串输入并通过将字符串与多个匹配来决定应该执行哪个操作模式。
它是一个强大而灵活的路由系统。如果使用得当,它可以通过解耦对象以及抽象导航路径和服务器请求来降低代码复杂性。
回答by Martijn
Another alternative, one that only does routing, and skips templates etc is Davis.js, see http://davisjs.com/. Only dependency is jQuery.
另一种选择,只做路由,跳过模板等是 Davis.js,见http://davisjs.com/。唯一的依赖是 jQuery。
回答by ebaxt
You could probably use deep linking with the jQuery address plugin.
您可能可以使用带有 jQuery地址插件的深层链接。