history : 历史管理组件
示例
介绍
- History 是一个单例类,服务于 Router 组件的,并作为全局路由服务,用于处理 hasChange 事件或 pushState ,匹配适合的路由,并触发回调函数。
使用方法
define(['jquery','util/router/1.0', 'util/history/1.0'], function($, Router, History){ // Instantiate the router var appRouter = new Router({ routes:{ "" : "initCallback", "help" : "helpCallback" }, history:false, initCallback:function(){ $('#routerVal').html("hash为空"); History.stop(); }, helpCallback:function(){ $('#routerVal').html("helpCallback"); } }); History.start(); });
公共方法
方法名称 | 入参说明 | 返回值 | 作用说明 |
---|---|---|---|
start (options) | options{JSON}
|
/ | 启动 history |
route (route, callback) | route {String}:路由规则 callback {Function}:路由回调函数 |
/ | 动态的创建或修改路由规则 |
stop () | / | / | 停用 history |
getHash () | / | hash 值 | 获取当前的 hash 值 |