IOS路由设计之JLRoutes

来源:互联网 发布:身份证破解软件 编辑:程序博客网 时间:2024/05/16 10:09

简介:对于一个业务逻辑复杂的应用,为更好实践组件化开发,设计一个优秀的路由层就显示的很重要。本文就JLRoutes实现页面之间MVVM模式下相互跳转设计思想及使用方法进行探讨。


JLRoutes 把页面组件等看作是请求资源URI,可把相应的视图转化为JLRoutes与程序配置的URL scheme组合起来以字典形式加入routes中。
所以需要在appdelegate文件中设定相应访问权限
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation

该方法既可对第三方试图打开本程序的app来源进行判断也可对本程序中相应的页面跳转(把页面文件看作是访问资源URI)进行判断。
+ (void)addRoute:(NSString *)routePattern handler:(BOOL (^)(NSDictionary<NSString *, NSString *> *parameters))handlerBlock ;
    [JLRoutes addRoute:@"/NaviPush/:controller" handler:^BOOL(NSDictionary<NSString *,NSString *> * _Nonnull parameters) {                UIViewController *vc = [[NSClassFromString(parameters[@"controller"]) alloc] init];        [currentVc.navigationController pushViewController:vc animated:YES];        return YES;    }];


如在需要跳转的界面以url方法访问即可:
NSString *customURL = @"TESTDEMO://NaviPush/SecondViewController;[[UIApplication sharedApplication] openURL:[NSURL URLWithString:customURL]];




原创粉丝点击