# HKRouter **Repository Path**: robbit_yang/HKRouter ## Basic Information - **Project Name**: HKRouter - **Description**: AppiOS自定义路由设计 App路由能解决那些问题: 1->点击推送消息,要求外部跳转到App内部一个很深层次的一个界面。比如微信的3D-Touch可以直接跳转到“我的二维码”。“我的二维码”界面在我的里面的第三级界面。或者再极端一点,产品需求给了更加变态的需求,要求跳转到App内部第十层的界面,怎么处理? 2->如何解除App组件之间和App页面之间的耦合性? 3->如何能统一iOS和Android两端的页面跳转逻辑?甚至如何能统一三端的请求资源的方式? 4->如果App出现bug了,如何不用JSPatch,就能做到简单的热修复功能? 5->如何在每个组件间调用和页面跳转时都进行埋点统计?每个跳转的地方都手写代码埋点?利用Runtime AOP ? 6->如何在App任何界面都可以调用同一个界面或者同一个组件?只能在AppDelegate里面注册单例来实现? 7->比如App出现问题了,用户可能在任何界面,如何随时随地的让用户强制登出?或者强制都跳转到同一个本地的error界面?如何让用户在任何界面,随时随地的弹出一个View? - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2021-06-01 - **Last Updated**: 2021-06-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # HKRouter ## 用路由进行页面跳转 ### 1.简单跳转,无参数 ```swift //路由规则 scheme://组件名称 scheme可自己定义 NSString * routerPattern = @"hk://Amodule"; ///注册路由 [HKRouter hk_registerRoutePattern:routerPattern targetName:@"BViewController"]; ///开始路由 [HKRouter hk_startRoute:[NSString stringWithFormat:@"%@",routerPattern]]; ``` ### 2.简单跳转,有参数 ```swift //路由规则 scheme://组件名称 scheme可自己定义 NSString * routerPattern = @"hk://Amodule"; ///注册路由 [HKRouter hk_registerRoutePattern:routerPattern targetName:@"BViewController"]; ///开始路由 [HKRouter hk_startRoute:[NSString stringWithFormat:@"%@?info1=Routerhk&info2=测试跳转&info3=123456789",routerPattern]]; ``` ### 3.跳转带回调 ```swift [HKRouter hk_registerRoutePattern:@"hk://Amodule/product/list" targetName:@"CViewController" handler:^(NSString * _Nonnull callTag, id _Nonnull parameters) { if ([callTag isEqualToString:@"update"]) { self.lbl1.text = [parameters valueForKey:@"editStr1"]; self.lbl2.text = [parameters valueForKey:@"editStr2"]; self.lbl3.text = [parameters valueForKey:@"editStr3"]; self.lbl1.textColor = [UIColor redColor]; self.lbl2.textColor = [UIColor redColor]; self.lbl3.textColor = [UIColor redColor]; } }]; [HKRouter hk_startRoute:@"hk://Amodule/product/list?title=C控制器"]; ``` ```swift - (void)backClick { NSMutableDictionary *param = [NSMutableDictionary dictionary]; [param setValue:@"Routerhk+editStr1" forKey:@"editStr1"]; [param setValue:@"测试跳转+editStr2" forKey:@"editStr2"]; [param setValue:@"123456789+editStr3" forKey:@"editStr3"]; self.handlerBlock(@"update", param); [self.navigationController popViewControllerAnimated:YES]; } ``` ### 5.present跳转配置 hk:// 后添加`hkPresent.` 即可实现 ```swift ///注册路由 [HKRouter hk_registerRoutePattern:@"hk://hkPresent.Amodule" targetName:@"BViewController"]; ///开始路由 [HKRouter hk_startRoute:@"hk://hkPresent.Amodule?info1=RouterDemo&info2=测试跳转&info3=123456789"]; ``` ### 4.控制器配置 ```swift //遵循路由协议:HKRouterProtocol #import "HKRouter.h" @interface BViewController : UIViewController @end //.m实现协议方法 +(instancetype)hk_createViewController:(id)parameters{ BViewController *bVC = [[BViewController alloc] init]; bVC.title = [parameters valueForKey:@"title"]; bVC.info1 = [parameters valueForKey:@"info1"]; bVC.info2 = [parameters valueForKey:@"info2"]; bVC.info3 = [parameters valueForKey:@"info3"]; return bVC; } ``` ## 效果图 ![效果图](https://images.gitee.com/uploads/images/2019/0716/203719_adf34d0a_1908551.gif "WkWebView封装.gif") # HKRouter [![CI Status](https://img.shields.io/travis/HJT916109796/HKRouter.svg?style=flat)](https://travis-ci.org/HJT916109796/HKRouter) [![Version](https://img.shields.io/cocoapods/v/HKRouter.svg?style=flat)](https://cocoapods.org/pods/HKRouter) [![License](https://img.shields.io/cocoapods/l/HKRouter.svg?style=flat)](https://cocoapods.org/pods/HKRouter) [![Platform](https://img.shields.io/cocoapods/p/HKRouter.svg?style=flat)](https://cocoapods.org/pods/HKRouter) ## Example To run the example project, clone the repo, and run `pod install` from the Example directory first. ## Requirements ## Installation HKRouter is available through [CocoaPods](https://cocoapods.org). To install it, simply add the following line to your Podfile: ```ruby pod 'HKRouter' ``` ## Author HJT916109796, 916109796@qq.com ## License HKRouter is available under the MIT license. See the LICENSE file for more info.