{"id":18264753,"url":"https://github.com/reactcomponentkit/routerexample","last_synced_at":"2025-04-09T01:42:11.267Z","repository":{"id":137750977,"uuid":"344816004","full_name":"ReactComponentKit/RouterExample","owner":"ReactComponentKit","description":"SwiftUI Router Example🚀","archived":false,"fork":false,"pushed_at":"2021-03-07T10:01:44.000Z","size":2066,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-14T19:53:54.286Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-05T13:15:36.000Z","updated_at":"2021-03-07T10:01:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"3873d40f-f8aa-47fe-b89f-7c6bd091556f","html_url":"https://github.com/ReactComponentKit/RouterExample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReactComponentKit%2FRouterExample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReactComponentKit%2FRouterExample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReactComponentKit%2FRouterExample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ReactComponentKit%2FRouterExample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ReactComponentKit","download_url":"https://codeload.github.com/ReactComponentKit/RouterExample/tar.gz/refs/heads/main","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:49.742Z","updated_at":"2025-04-09T01:42:11.223Z","avatar_url":"https://github.com/ReactComponentKit.png","language":"Swift","readme":"# RouterExample\n\n[SwiftUI Router](https://github.com/ReactComponentKit/Router) Example🚀\n\n## Example\n\n![](./example.gif)\n\n## Example Code\n\n```swift\nimport SwiftUI\nimport Router\nimport Defaults\n\n@main\nstruct RouterExampleApp: App {\n    \n    @Default(.isFirstLaunch)\n    var isFirstLaunch\n    \n    var body: some Scene {\n        WindowGroup {\n            RouterRootView { router in\n                Switch(isFirstLaunch)\n                    .Case(true) { _ in\n                        OnboardingView()\n                    }\n                    .Case(false) { _ in\n                        ContentView()\n                    }\n                    .Else {\n                        EmptyView()\n                    }\n                    .navigationBarHidden(true)\n            }\n            .path(\"myapp://onboarding\") { data in\n                Switch(data.page.flatMap { Int($0) })\n                    .Case(1) { _ in\n                        OnboardingView()\n                    }\n                    .Case(2) { _ in\n                        OnboardingView2()\n                    }\n                    .Else {\n                        EmptyView()\n                    }\n                    .navigationBarHidden(true)\n            }\n            .path(\"myapp://content\") { data in\n                Switch(data.as_root.flatMap { Bool($0) })\n                    .Case(true) { _ in\n                        ContentView()\n                            .asRouterRootView()\n                    }\n                    .Else {\n                        ContentView()\n                    }\n                    .navigationBarHidden(true)\n            }\n            .path(\"myapp://counter\") { data in\n                CounterView(count: data.bindings.count)\n                    .navigationBarHidden(true)\n            }\n            .path(\"myapp://color\") { data in\n                If(data.color).Let { color in\n                    ColorView(color:  MyColor.from(string: color))\n                }\n                .navigationBarHidden(true)\n//                Switch(data.color)\n//                    .Case(\"red\") { color in\n//                        ColorView(color:  MyColor.from(string: color))\n//                            .navigationBarHidden(true)\n//                    }\n//                    .Case(\"green\") { color in\n//                        ColorView(color:  MyColor.from(string: color))\n//                            .navigationBarHidden(true)\n//                    }\n//                    .Else {\n//                        Text(\"OMG\")\n//                    }\n            }\n        }\n    }\n}\n```\n\n## ColorView\n\n```swift\nimport SwiftUI\nimport Router\n\nenum MyColor: String {\n    case red\n    case green\n    case blue\n    case yellow\n    case purple\n    case white\n}\n\nstruct ColorView: View {\n    @EnvironmentObject\n    var router: Router\n    \n    var color: MyColor = .white\n    \n    var body: some View {\n        VStack(spacing: 48) {\n            switch color {\n            case .red:\n                Button(\"Go to Green\") {\n                    router.route(\"myapp://color?color=green\", .push)\n                }\n            case .green:\n                Button(\"Go to Blue\") {\n                    router.route(\"myapp://color?color=blue\", .push)\n                }\n            case .blue:\n                Button(action: { router.route(\"myapp://color?color=yellow\", .push) }) {\n                    Text(\"Go to Yellow\")\n                        .foregroundColor(.white)\n                }\n            case .yellow:\n                Button(\"Go to Purple\") {\n                    router.route(\"myapp://color?color=purple\", .push)\n                }\n            case .purple:\n                Button(\"Go to White\") {\n                    router.route(\"myapp://color?color=white\", .push)\n                }\n            default:\n                Button(\"Go to Red\") {\n                    router.route(\"myapp://color?color=red\", .push)\n                }\n            }\n            \n            Button(action: { router.route(\"myapp://content.as.root\", .sheet) }) {\n                Text(\"Go to Sheet\")\n                    .foregroundColor(.black)\n            }\n                        \n            Button(action: { router.popToRoot() }) {\n                Text(\"Pop To Root\")\n                    .foregroundColor(.black)\n            }\n        }\n        .frame(maxWidth: .infinity, maxHeight: .infinity)\n        .background(makeColor(color: color).ignoresSafeArea())\n    }\n    \n    private func makeColor(color: MyColor) -\u003e Color {\n        switch color {\n        case .red:\n            return Color.red\n        case .blue:\n            return Color.blue\n        case .green:\n            return Color.green\n        case .yellow:\n            return Color.yellow\n        case .purple:\n            return Color.purple\n        case .white:\n            return Color.white\n        }\n    }\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactcomponentkit%2Frouterexample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freactcomponentkit%2Frouterexample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactcomponentkit%2Frouterexample/lists"}