{"id":21010945,"url":"https://github.com/hfhbd/routing-compose","last_synced_at":"2025-05-15T03:32:01.104Z","repository":{"id":36952826,"uuid":"375056637","full_name":"hfhbd/routing-compose","owner":"hfhbd","description":"Routing feature for Compose Web, Compose HTML and Desktop","archived":false,"fork":false,"pushed_at":"2025-04-28T05:51:01.000Z","size":1117,"stargazers_count":151,"open_issues_count":15,"forks_count":14,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-28T06:33:05.323Z","etag":null,"topics":["compose-desktop","compose-html","compose-web","kotlin"],"latest_commit_sha":null,"homepage":"https://routing.softwork.app/","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hfhbd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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,"zenodo":null},"funding":{"github":"hfhbd"}},"created_at":"2021-06-08T15:22:41.000Z","updated_at":"2025-04-28T05:51:03.000Z","dependencies_parsed_at":"2023-09-27T10:57:45.166Z","dependency_job_id":"a92fe7ad-545e-45bc-827f-6f95b0ebb475","html_url":"https://github.com/hfhbd/routing-compose","commit_stats":null,"previous_names":[],"tags_count":58,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hfhbd%2Frouting-compose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hfhbd%2Frouting-compose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hfhbd%2Frouting-compose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hfhbd%2Frouting-compose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hfhbd","download_url":"https://codeload.github.com/hfhbd/routing-compose/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254266303,"owners_count":22042082,"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":["compose-desktop","compose-html","compose-web","kotlin"],"created_at":"2024-11-19T09:24:39.479Z","updated_at":"2025-05-15T03:32:00.778Z","avatar_url":"https://github.com/hfhbd.png","language":"Kotlin","readme":"# RoutingCompose\n\nRouting feature for [Compose Web, Compose HTML and Desktop](https://github.com/Jetbrains/compose-jb)\n\n## Install\n\nThis package is uploaded to MavenCentral.\n\n````kotlin\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    implementation(\"app.softwork:routing-compose:LATEST\")\n}\n````\n\n## Usage\n\nExample with `HashRouter`, `BrowserRouter` and `DesktopRouter` will be implemented in the same manner.\n\n```kotlin\nHashRouter(initPath = \"/hello\") { // or BrowserRouter(initPath = \"/hello\") {\n    route(\"/hello\") {\n        Text(\"Hello World\")\n    }\n}\n```\n\nMore complex sample showing `Router.current`, query parameters, `@Composable` support and dynamic routing with `mutableState`:\n\n```kt\n@Composable\nfun SomeContainer(content: @Composable () -\u003e Unit) {\n    header()\n    content()\n    footer()\n}\n\nHashRouter(initPath = \"/users\") { // or BrowserRouter(initPath = \"/users\") {\n    val enableFeature by remember { mutableStateOf(false) }\n    route(\"/users\") {\n        SomeContainer {\n            int { userID -\u003e\n                Text(\"User with $userID\")\n            }\n            noMatch {\n                Text(\"User list\")\n            }\n        }\n    }\n    if (enableFeature) {\n        route(\"/hiddenFeature\") {\n            val params: Map\u003cString, List\u003cString\u003e\u003e? = parameters?.map\n            val router = Router.current\n            Text(\"Hidden feature\")\n        }\n    }\n    noMatch {\n        Text(\"Hello World\")\n    }\n}\n```\n\nRoutingCompose offers three routing implementations, `HashRouter`, `BrowserRouter` and `DesktopRouter`.\n\n[This article](https://blog.bitsrc.io/using-hashed-vs-nonhashed-url-paths-in-single-page-apps-a66234cefc96) provides a good explanation of the difference between each browser routing strategy.\n\n### HashRouter\n\n`HashRouter` is used for hashed urls (e.g. yoursite.com/#/path).\nThis strategy requires no additional setup to work on a single page compose-web application.\nSome SaaS providers, like GitHub Pages, do not offer configuration options, so you have to use `HashRouter`.\n\n### BrowserRouter\n\n`BrowserRouter` is used for traditional urls (e.g. yoursite.com/path).\nUsing this strategy will require additional work on a single page compose-web application, requiring you to implement a catch-all strategy to return the same html resource for all paths.\nThis strategy will be different for different server configurations.\n\n#### Development usage:\n\nThe `browser` target for Kotlin/JS uses [webpack-dev-server](https://github.com/webpack/webpack-dev-server) as a local development server.\nWe need our webpack config to serve `index.html` (or your primary html file) for all paths to work with `BrowserRouter`.\nThis is done in webpack-dev-server through the webpack config's [devServer.historyApiFallback](https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback) flag.\n\nThe Kotlin webpack DSL currently [does not support the `historyApiFallback` flag](https://github.com/JetBrains/kotlin/blob/master/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/targets/js/webpack/KotlinWebpackConfig.kt#L165), but we can add it through additional [webpack configuration files](https://kotlinlang.org/docs/js-project-setup.html#webpack-configuration-file) that will be merged with the auto-generated `webpack.config.js` when building.\n\n##### Instructions\n\nFirst, create a directory in the top-most project directory named `webpack.config.d`.\n\nCreate a new `.js` file containing a `config.devServer` configuration setting `historyApiFallback = true`.\nYou can name this file any name you wish, it will be merged into the project's main `webpack.config.js`.\n\n```javascript\n// YourProject/webpack.config.d/devServerConfig.js\n\nconfig.devServer = {\n    ...config.devServer, // Merge with other devServer settings\n    \"historyApiFallback\": true\n};\n```\n\nThen run your web app, and it should route all paths to a valid route.\nYou can confirm this by refreshing or manually entering a path.\n\n### DesktopRouter\n\nYou can use the `DesktopRouter` implementation to add a routing feature to your Compose Desktop application.\nThe `DesktopRouter` contains a special `navigateBack` method.\n\n```kotlin\nWindow {\n    DesktopRouter(\"/\") {\n        string {\n            Column {\n                Text(\"Hello $it\")\n                val router = Router.current\n                Button(onClick = { router.navigateBack() }) {\n                    Text(\"Go back\")\n                }\n            }\n        }\n        noMatch {\n            val router = Router.current\n            Button(onClick = {\n                router.navigate(to = \"/World\")\n            }) {\n                Text(\"Navigate to World\")\n            }\n        }\n    }\n}\n```\n","funding_links":["https://github.com/sponsors/hfhbd"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhfhbd%2Frouting-compose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhfhbd%2Frouting-compose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhfhbd%2Frouting-compose/lists"}