{"id":13658123,"url":"https://github.com/xxfast/Decompose-Router","last_synced_at":"2025-04-24T08:31:20.686Z","repository":{"id":65795108,"uuid":"599478957","full_name":"xxfast/Decompose-Router","owner":"xxfast","description":"A Compose-multiplatform navigation library that leverage Decompose to create an API inspired by Conductor","archived":false,"fork":false,"pushed_at":"2024-12-04T09:42:11.000Z","size":31106,"stargazers_count":232,"open_issues_count":11,"forks_count":9,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-12-04T10:20:05.915Z","etag":null,"topics":["android","compose-multiplatform","decompose","jetpack-compose","kotlin","kotlin-multiplatform","navigation"],"latest_commit_sha":null,"homepage":"https://xxfast.github.io/Decompose-Router/","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xxfast.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-02-09T08:16:00.000Z","updated_at":"2024-12-04T09:42:15.000Z","dependencies_parsed_at":"2023-12-27T07:46:38.579Z","dependency_job_id":"4b80165d-ef23-4122-9185-1c1bbcaf969c","html_url":"https://github.com/xxfast/Decompose-Router","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxfast%2FDecompose-Router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxfast%2FDecompose-Router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxfast%2FDecompose-Router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxfast%2FDecompose-Router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xxfast","download_url":"https://codeload.github.com/xxfast/Decompose-Router/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250591985,"owners_count":21455476,"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":["android","compose-multiplatform","decompose","jetpack-compose","kotlin","kotlin-multiplatform","navigation"],"created_at":"2024-08-02T05:00:56.552Z","updated_at":"2025-04-24T08:31:20.670Z","avatar_url":"https://github.com/xxfast.png","language":"Kotlin","readme":"\n# Decompose Router\n\n\u003cpicture\u003e\n  \u003csource media=\"(prefers-color-scheme: dark)\" srcset=\"https://user-images.githubusercontent.com/13775137/236108051-73a54cd2-839a-4113-a8c0-25eeaad6b673.svg\"\u003e\n  \u003csource media=\"(prefers-color-scheme: light)\" srcset=\"https://user-images.githubusercontent.com/13775137/236108679-0ed87db8-fc1e-4f23-bcf7-3c10eeedc82a.svg\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/13775137/236108679-0ed87db8-fc1e-4f23-bcf7-3c10eeedc82a.svg\" height=\"128\" align=\"right\"\u003e \n\u003c/picture\u003e\n\n[![Kotlin Alpha](https://kotl.in/badges/alpha.svg)](https://kotlinlang.org/docs/components-stability.html)\n[![Build](https://github.com/xxfast/Decompose-Router/actions/workflows/build.yml/badge.svg)](https://github.com/xxfast/Decompose-Router/actions/workflows/build.yml)\n[![Kotlin](https://img.shields.io/badge/Kotlin-2.0.20-blue.svg?style=flat\u0026logo=kotlin)](https://kotlinlang.org)\n[![Maven Central](https://img.shields.io/maven-central/v/io.github.xxfast/decompose-router?color=blue)](https://search.maven.org/search?q=g:io.github.xxfast)\n\n![badge-android](http://img.shields.io/badge/platform-android-6EDB8D.svg?style=flat)\n![badge-wearos](http://img.shields.io/badge/platform-wearos-8ECDA0.svg?style=flat)\n![badge-desktop](http://img.shields.io/badge/platform-desktop-4D76CD.svg?style=flat)\n![badge-ios](http://img.shields.io/badge/platform-ios-EAEAEA.svg?style=flat)\n![badge-browser-js](https://img.shields.io/badge/platform-js-F8DB5D.svg?style=flat)\n![badge-browser-wasm](https://img.shields.io/badge/platform-wasm-F8DB5D.svg?style=flat)\n\nA Compose-multiplatform navigation library that leverage [Decompose](https://github.com/arkivanov/Decompose) to create an API inspired by [Conductor](https://github.com/bluelinelabs/Conductor)\n\nA detailed breakdown available in this [Medium article](https://proandroiddev.com/diy-compose-multiplatform-navigation-with-decompose-94ac8126e6b5)\n\n## Features\n- 🚏 A `Router` that manages a stack, pages or slot for your screen configurations\n- 📦 `rememberOnRoute()` lets you retain your view model across configuration changes and gets cleared when the user leaves the screen\n- 🚉 Multiplatform! Supports Android, WearOS, Desktop, iOS and Web\n\n## At a glance\n\n\n```kotlin\n// Declare your screen configurations as @Serializable for type-safety\n@Serializable\nsealed class Screen : Parcelable {\n  data object List : Screen()\n  data class Details(val detail: String) : Screen()\n}\n\n@Composable\nfun ListDetailScreen() {\n  // Create a router with a stack of screen configurations 🚏\n  val router: Router\u003cScreen\u003e = rememberRouter { listOf(List) }\n\n  // Hoist your screens for each configuration 🏗️\n  RoutedContent(router = router) { screen -\u003e\n    when (screen) {\n      List -\u003e ListScreen(\n        // Navigate by pushing new configurations on the router 🧭\n        onSelectItem = { detail -\u003e router.push(detail) }\n      )\n\n      is Details -\u003e DetailsScreen(screen.detail)\n    }\n  }\n}\n\n@Composable\nfun DetailsScreen(detail: String) {\n  // 📦 Scope an instance (a view model, a state-holder or whatever) to a route with [rememberOnRoute] \n  // This makes your instances survive configuration changes (on android) 🔁\n  // And holds-on the instance as long as it is in the backstack 🔗\n  // Pass in key if you want to reissue a new instance when key changes 🔑 (optional) \n  val viewModel: DetailViewModel = rememberOnRoute(key = detail) { // this: RouterContext \n    DetailViewModel(this, detail)\n      // Optional, if you want your coroutine scope to be cancelled when the screen is removed from the backstack\n      .apply { doOnDestroy { cancel() } }      \n  }\n\n  val state: DetailState by viewModel.states.collectAsState()\n  \n  Text(text = state.detail)\n}\n\nclass DetailViewModel(context: RouterContext, detail: String): CoroutineScope {\n  // Optional, if you want to scope your coroutines to the lifecycle of this screen\n  override val coroutineContext: CoroutineContext = Dispatchers.Main + SupervisorJob()\n  \n  // Optional, if you want your state to survive process death ☠️ \n  // Derive your initial state from [RouterContext.state] \n  private val initialState: DetailState = context.state(DetailState(detail)) { states.value }\n  private val stateFlow = MutableStateFlow(initialState)\n  \n  val states: StateFlow\u003cDetailState\u003e = stateFlow\n}\n```\n\n### Installation\n\nDecompose-Router is published on Maven Central. Latest version [![Maven Central](https://img.shields.io/maven-central/v/io.github.xxfast/decompose-router?color=blue)](https://search.maven.org/search?q=g:io.github.xxfast)\n```kotlin\nrepositories { \n  mavenCentral()\n  // or for snapshot builds\n  maven(\"https://s01.oss.sonatype.org/content/repositories/snapshots/\")\n}\n```\n\n\u003e **Note** - Check for compatible versions of Decompose and Compose in the [version catalog](gradle/libs.versions.toml)\n\n```toml\n[versions]\ndecompose-router = \"\u003cversion\u003e\"\n\n[libraries]\n# For Jetpack Compose / Compose Multiplatform\ndecompose-router = { module = \"io.github.xxfast:decompose-router\", version.ref = \"decompose-router\" }\n\n# For Compose Wear\ndecompose-router-wear = { module = \"io.github.xxfast:decompose-router-wear\", version.ref = \"decompose-router\" }\n```\n\nRead more\n - Documentation [here](https://xxfast.github.io/Decompose-Router/)\n - API Reference [here](https://xxfast.github.io/Decompose-Router//docs/)\n\n## Licence\n\n    Copyright 2024 Isuru Rajapakse\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n","funding_links":[],"categories":["Multiplatform","Libraries"],"sub_categories":["Multiplatform libraries","🏗 Architecture"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxxfast%2FDecompose-Router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxxfast%2FDecompose-Router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxxfast%2FDecompose-Router/lists"}