{"id":18264740,"url":"https://github.com/reactcomponentkit/bkrouter","last_synced_at":"2025-07-07T13:34:58.150Z","repository":{"id":56902964,"uuid":"148962761","full_name":"ReactComponentKit/BKRouter","owner":"ReactComponentKit","description":"BKRouter is a navigator for UIViewControllers on iOS.","archived":false,"fork":false,"pushed_at":"2018-09-16T11:27:54.000Z","size":63,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-14T19:53:54.235Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/ReactComponentKit/BKRouter","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ReactComponentKit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-16T04:21:32.000Z","updated_at":"2018-09-16T11:27:55.000Z","dependencies_parsed_at":"2022-08-21T01:50:51.715Z","dependency_job_id":null,"html_url":"https://github.com/ReactComponentKit/BKRouter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReactComponentKit%2FBKRouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReactComponentKit%2FBKRouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReactComponentKit%2FBKRouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReactComponentKit%2FBKRouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ReactComponentKit","download_url":"https://codeload.github.com/ReactComponentKit/BKRouter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247958710,"owners_count":21024821,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T11:15:47.114Z","updated_at":"2025-04-09T01:42:11.206Z","avatar_url":"https://github.com/ReactComponentKit.png","language":"Swift","readme":"# BKRouter\n\nBKRouter is a navigator for UIViewControllers on iOS. It navigates the UIViewControllers via a url string.   \n\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/ReactComponentKit/BKRouter/master/art/BKRouter.png\" /\u003e\n\u003c/div\u003e \n\n\n## Installation\n\nYou can install BKRouter via cocoapod.\n\n```swift\npod 'BKRouter'\n```\n\n## How to Use it?\n\nYou should make a route map and register it to Router. Route map is a implementation of Routerable protocol. A Route map for ColorViewController is like below:\n\n```swift\nimport UIKit\nimport BKRouter\n\nclass RouteColor: Routerable {\n    static func route(scheme: String, host: String, params: [String : String], userData:[String: Any]?) -\u003e UIViewController? {\n        // storyboard\n        let vc = UIStoryboard(name: \"Main\", bundle: nil).instantiateViewController(withIdentifier: \"ColorViewController\")\n        \n        if let colorVC = vc as? ColorViewController {\n            if let color = params[\"color\"] {\n                switch color {\n                case \"red\":\n                    colorVC.color = UIColor.red\n                case \"blue\":\n                    colorVC.color = UIColor.blue\n                case \"green\":\n                    colorVC.color = UIColor.green\n                default:\n                    colorVC.color = UIColor.white\n                }\n            }\n        }\n        return vc\n    }\n}\n```\n\nIf you use a host as \"myapp\", you can map \"myapp://color\" to RouteColor like below:\n\n```swift\nRouter.shared.map(url: \"myapp://color?color=$value\", to: RouteColor.self)\n```\n\nIn the above code, the `$value` is the value that is passed via url string. If you have more complex data, you can use userData when you route by using Router like below:\n\n```swift\nRouter.shared.push(from: self, to: \"myapp://color?color=red\", userData: [\"A\": 1])\n```\n\nYou can modulate your app into framework fragments. If DomainA framework has many scenes as UIViewControllers, you can define a Route for routing DomainA.\n\n```swift\nimport Foundation\nimport BKRouter\n\npublic class RouteDomainA: Routerable {\n    public static func route(scheme: String, host: String, params: [String : String], userData:[String: Any]?) -\u003e UIViewController? {\n        // storyboard\n        guard let items = userData?[\"items\"] as? [String] else { return nil }\n        let viewModel = DomainAViewModel(havyItemArray: items)\n        let vc = DomainAViewController(viewModel: viewModel)\n        return vc\n    }\n}\n```\n\nOf course, you should register above RouteDomainA to Router like below:\n\n```swift\nRouter.shared.map(url: \"myapp://domainA\", to: RouteDomainA.self)\n```\n\n## Register Routes to Router\n\nYou should register route maps to Router. AppDelegate is a good place to do it. \n\n```swift\nfunc application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -\u003e Bool {\n        \n    Router.shared.map(url: \"myapp://main?title=$value\u0026a=$v1\u0026b=v2\", to: RouteMain.self)\n    Router.shared.map(url: \"myapp://color?color=$value\", to: RouteColor.self)\n    Router.shared.map(url: \"myapp://domainA\", to: RouteDomainA.self)\n    Router.shared.map(url: \"myapp://domainB?title=$value\", to: RouteDomainB.self)\n    return true\n}\n```\n\n## Route it\n\nYou can route UIViewControllers by using Router. \n\n```swift\n@IBAction func clickedRedButton(_ sender: Any) {\n    Router.shared.push(from: self, to: \"myapp://color?color=red\", userData: [\"A\": 1])\n}\n    \n@IBAction func clickedGreenButton(_ sender: Any) {\n    Router.shared.push(from: self, to: \"myapp://color?color=green\")\n}\n    \n@IBAction func clickedBlueButton(_ sender: Any) {\n    Router.shared.push(from: self, to: \"myapp://color?color=blue\")\n}\n\n@IBAction func clickedNextButton(_ sender: Any) {\n    Router.shared.push(from: self, to: \"myapp://domainB?title=Hello\")\n}\n\n@IBAction func clickedNextButton(_ sender: Any) {\n    let items = [\n        \"Lorem Ipsum is simply dummy text of the printing and typesetting industry.\",\n        \"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,\",\n        \"when an unknown printer took a galley of type and scrambled it to make a type specimen book.\",\n        \"It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.\",\n        \"It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,\",\n        \"and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.\"\n    ]\n\n    Router.shared.push(from: self, to: \"myapp://domainA\", userData: [\"items\": items])\n}\n```\n\n## Handle Deeplinking\n\nYou can also handle deeplinks using Router. First of all, you should register an URLType scheme for your deeplink.\n\n```xml\n\u003ckey\u003eCFBundleURLTypes\u003c/key\u003e\n\u003carray\u003e\n   \u003cdict\u003e\n      \u003ckey\u003eCFBundleURLName\u003c/key\u003e\n      \u003cstring\u003ecom.github.skyfe79.bkrouter\u003c/string\u003e\n      \u003ckey\u003eCFBundleURLSchemes\u003c/key\u003e\n      \u003carray\u003e\n         \u003cstring\u003emyapp\u003c/string\u003e\n      \u003c/array\u003e\n   \u003c/dict\u003e\n\u003c/array\u003e\n```\n\nYou can handle deeplinks like belows:\n\n```swift\nfunc application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -\u003e Bool {\n    Router.shared.replace(to: url.absoluteString, wrapNavigationController: true)\n    return true\n}\n```\n\n### Test Deeplinks with iOS Simulator\n\nYou can test deeplinks using iOS simulator from your terminal.\n\n 1. Run the above example app.\n 2. Open the terminal.\n 3. type the below commands.\n\n```\nxcrun simctl openurl booted 'myapp://main'\nxcrun simctl openurl booted 'myapp://domainB?title=HELLO'\nxcrun simctl openurl booted 'myapp://color?color=red'\nxcrun simctl openurl booted 'myapp://domainB?title=%EC%95%88%EB%85%95%ED%95%98%EC%84%B8%EC%9A%94'\n...\n```\n\n## MIT License\n\nMIT License\n\nCopyright (c) 2018 Sungcheol Kim, https://github.com/ReactComponentKit/BKRouter\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactcomponentkit%2Fbkrouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freactcomponentkit%2Fbkrouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactcomponentkit%2Fbkrouter/lists"}