path.js 简单 轻量级的 Web 浏览器路由库
PathJS 是一个轻量级的客户端路由库,允许您使用 hash 或者是 HTML5 pushState 创建 SPA 单页应用程序。
特点
- 简单轻量级
- 全面支持 HTML5 History API,如果浏览器不支持,可以优雅的降级使用普通链接。
- 支持 根路由、救援方法、参数化路由、可选路由组件(动态路由)和面向对象的编程
- 兼容所有主流浏览器(在 Firefox 3.6、Firefox 4.0、Firefox 5.0、Chrome 9、Opera 11、IE7、IE8、IE9 上测试)
- 独立于所有第三方库,但对所有第三方库都很好的兼容
使用 PathJS
function clearPanel(){// You can put some code in here to do
// fancy DOM transitions, such as fade-out or slide-in.
}
Path.map("#/users").to(function(){
alert("Users!");
});
Path.map("#/comments").to(function(){
alert("Comments!");
}).enter(clearPanel);
Path.map("#/posts").to(function(){
alert("Posts!");
}).enter(clearPanel);
Path.root("#/posts");
Path.listen();
Github 地址:https://github.com/mtrpcic/pathjs
以上是 path.js 简单 轻量级的 Web 浏览器路由库 的全部内容, 来源链接: www.h5w3.com/232449.html