Swift Routing framework (Spider)Github.com/SaveFree/Sp…)

thought

1. Manage all routes in a project through subroutes (modular). Subroutes can be classified into H5, RN, and Native. Mainly for some page jump, can be customized to achieve the jump function. Currently, data interaction is one-way.

2. Each sub-route is registered with the primary route. The final mapping relationship is centrally managed by the main route.

3. In child routes, you need to inherit the Base class to add custom methods.

4. Primary routes map all child routes. Method of finding child routes through routing objects. Finally realize the jump.

// The main route is singleton staticletShared = RouteManager() // Subrouting base class TypeAlias RouteModuleCallback = ([String: String]) -> () class RouteBaseModule { public func moduleName() -> String {return "base"
    }
    
    public func services() -> [ModuleModel]? {
        returnnil } public func handlerUrl(args: [String: String], callback: @escaping RouteModuleCallback) {callback(args)}} @escaping RouteModuleCallback) {callback(args)}} @escaping RouteModuleCallback) {callback(args)}} class XXRouteXXXModule: RouteBaseModule { override func moduleName() -> String {return "xxx"
    }
    
    override func services() -> [ModuleModel]? {
        var list = [ModuleModel]()
        list.append(ModuleModel(route: "xxx://xxxx", selector: #selector(gotoXXX(params:))))
        return list
    }

    @objc func gotoXXX(params: [String: String]) {
        self.handlerUrl(args: params, callback: {
            (params) in
             //
            print("XXXXXX")})}} / / registered RouteManager. Shared. RegisterModule (module: XXRouteXXXModule ()) / / jump RouteManager Shared. The route (routeStr:"xxx://xxxx", extraArgs: nil)

Copy the code

(spiders github.com/SaveFree/Sp…).