{"id":13609107,"url":"https://github.com/denisidoro/krouter","last_synced_at":"2025-06-14T15:05:53.558Z","repository":{"id":151360985,"uuid":"68486240","full_name":"denisidoro/krouter","owner":"denisidoro","description":"A lightweight Android activity router","archived":false,"fork":false,"pushed_at":"2018-04-24T02:51:58.000Z","size":70,"stargazers_count":121,"open_issues_count":2,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-02T03:51:07.262Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","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/denisidoro.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}},"created_at":"2016-09-18T00:55:06.000Z","updated_at":"2024-03-31T03:49:27.000Z","dependencies_parsed_at":"2024-01-07T04:48:11.847Z","dependency_job_id":null,"html_url":"https://github.com/denisidoro/krouter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/denisidoro/krouter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denisidoro%2Fkrouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denisidoro%2Fkrouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denisidoro%2Fkrouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denisidoro%2Fkrouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/denisidoro","download_url":"https://codeload.github.com/denisidoro/krouter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/denisidoro%2Fkrouter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259835393,"owners_count":22918980,"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-08-01T19:01:32.500Z","updated_at":"2025-06-14T15:05:53.534Z","avatar_url":"https://github.com/denisidoro.png","language":"Kotlin","funding_links":[],"categories":["\u003ca name=\"utility\"\u003e\u003c/a\u003eUtility \u003csup\u003e[Back ⇈](#contents)\u003c/sup\u003e","Kotlin"],"sub_categories":[],"readme":"# Krouter\nA lightweight Android activity router written in Kotlin.\n\n![crossroads](https://cloud.githubusercontent.com/assets/3226564/18612759/e81f369c-7d38-11e6-9a3d-b9da6fdc6944.png)\n\n### Basic usage\n\n```kotlin\n// anywhere in the app, preferably on application creation\nval krouter = Krouter.from(context, hashMapOf(\n    \"user/:id/likes\" to UserLikesActivity::class.java\n))\n\n// anywhere that can access the val above\nkrouter.start(\"user/42/likes\") // this will start UserLikesActivity\n\n// inside UserLikesActivity, possibly inside onCreate()\nval id: Int = intent.getIntExtra(\"id\", 0) // 42\n```\n\n### Adding more extras\n\nIn order to add more extras to the intent, one can do the following:\n```kotlin\nkrouter.getRouter(\"user/42/likes\")!!\n    .withIntent { it.putExtra(\"name\", \"John\") }\n    .start()\n```\n\n### Starting for result\n\nIn order to set a request code:\n```kotlin\nkrouter.getRouter(\"user/42/likes\")!!\n    .startForResult(activity, 123) // 123 is the request code\n```\n\n### Advanced routing configuration\n\nIt is possible to instantiate Krouter establishing a regular expression that the parameter must specify:\n```kotlin\nval krouter = Krouter(context, hashMapOf(\n    Route(\"user/:id/likes\", hashMapOf(\n        \"id\" to Schema(\"^[0-9]{2}$\")\n    )) to UserLikesActivity::class.java\n)\n```\n\nThere are default implementations for integer, float, double, long, char:\n```kotlin\n// the constants must be statically imported from Schema.Type\nRoute(\"user/:id/likes\", hashMapOf(\"id\" to Schema(INT)))\nRoute(\"my/balance/:value\", hashMapOf(\"value\" to Schema(FLOAT)))\n```\n\nIf no schema is defined, Krouter will try to infer the type accordingly.\nIf no schema is suitable, the param will be coerced to a String.\n\n### Interceptor\nYou can add some interceptors to Krouter:\n\n```Kotlin\n// If you are not logged in, go to login\nkrouter.addInterceptor(object : Interceptor {\n    override fun intercept(chain: Interceptor.Chain): Router? {\n\n        val route = chain.request()\n        if(route?.url == \"user/:id\" \u0026\u0026 !login) {\n            val target = chain.proceed(route)\n            val router = krouter.getRouter(\"login\")\n            router?.intent?.putExtra(\"nav\", target?.url)\n            router?.update()\n            return router\n        }\n        return chain.proceed(route)\n    }\n\n})\n```\n\n### Installation\n\nAdd the dependency:\n```gradle\ndependencies {\n    compile 'com.github.denisidoro.github:krouter:0.0.2'\n}\n```\n\n### Best practices\n\n- **Use dependency injection**: Krouter was idealized to be used in conjunction with Dagger.\n- **Compose routers**: say you have an activity flow in your app that's only accessible to users who are admin, for instance. If you don't want to deal with a huge routing map that has routes *all* flows, then create multiple Krouter instances. `val globalKrouter` and `@AdminScope val adminKrouter`, for example.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenisidoro%2Fkrouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdenisidoro%2Fkrouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdenisidoro%2Fkrouter/lists"}