PathJS轻量级 Web 浏览器路由
PathJS 是个轻量级的,客户端路由库,允许你创建 “单页”应用,使用 Hashbangs 和/或者 HTML5 pushState。
主要特性:
轻量级
支持 HTML5 History API, 'onhashchange' 方法和平滑的 degredation
支持根路由,rescue methods, paramaterized routes, optional route components (dynamic routes), and Aspect Oriented Programming
经过了很好的测试 (测试示例请看
./tests目录)兼容所有主流浏览器(通过了 Firefox 3.6, Firefox 4.0, Firefox 5.0, Chrome 9, Opera 11, IE7, IE8, IE9 的测试)
独立于所有第三方库,但是又能很好的与第三方库结合使用
简单示例:
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();
评论
