SDRouterDemo
SDRouter use for decoupling.use simple code bridge native to native or H5 to native by AppSchema with parameter, like this "asone://oneController?url=http://www.baidu.com" SDRouter 可以用來在模塊與模塊間的解耦及通信,也可以作為H5和原生的交互、跳轉(zhuǎn)、傳參。
hello1.gif
原生跳原生帶參數(shù)使用(可以參考demo):
1.給需要使用url跳轉(zhuǎn)的控制器 定義url如
NSString *const OneController = @"asone://oneController";
2.在該控制器+load方法中添加如下代碼
+ (void)load {
[[SDRouter shareRutor] addPaten:OneController callback:^(SDRouterContext *context) {
NSLog(@"優(yōu)品財(cái)富: %@",context.paramters);
OneViewController *textOneVc = [[OneViewController alloc] init];
textOneVc.navigationItem.title = context.paramters[@"title"];
[context.topNavigationController pushViewController:textOneVc animated:YES];
}];
}
3.跳轉(zhuǎn)到該控制器
NSDictionary *param = @{@"title":@"as_one"};
NSURL *url = SDURLRouteQueryLink(OneController, param);
[[SDRutor shareRutor] rutor:url];
H5跳原生帶參數(shù)使用(可以參考demo):
1.步驟同上1
2.步驟同上2
3.前端人員需要在頁面元素中添加script代碼如下
function jump(){
window.location="asone://threeController?title=as??three";
}
覺的有用的話記得給一顆?
github地址
其他說明:
其實(shí)前端不一定非要使用window.location,也可以直接給個(gè)url內(nèi)鏈跳轉(zhuǎn)也是一樣的。這和該庫內(nèi)部實(shí)現(xiàn)方式有關(guān),只是上面的腳本更加通用,兩種方式的區(qū)別,會(huì)在原理篇講解。