{"id":13498258,"url":"https://github.com/ssseasonnn/RxRouter","last_synced_at":"2025-03-29T00:34:12.598Z","repository":{"id":119569242,"uuid":"128751737","full_name":"ssseasonnn/RxRouter","owner":"ssseasonnn","description":"A lightweight, simple, smart and powerful Android routing library.","archived":false,"fork":false,"pushed_at":"2019-07-23T14:20:13.000Z","size":194,"stargazers_count":322,"open_issues_count":1,"forks_count":27,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-10-31T15:38:34.384Z","etag":null,"topics":["router","rxjava"],"latest_commit_sha":null,"homepage":"","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/ssseasonnn.png","metadata":{"files":{"readme":"README.ch.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}},"created_at":"2018-04-09T10:02:12.000Z","updated_at":"2024-03-27T14:56:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"78b5f35e-bcf6-437f-abbf-ad6701ba0bdb","html_url":"https://github.com/ssseasonnn/RxRouter","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssseasonnn%2FRxRouter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssseasonnn%2FRxRouter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssseasonnn%2FRxRouter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssseasonnn%2FRxRouter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ssseasonnn","download_url":"https://codeload.github.com/ssseasonnn/RxRouter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246122259,"owners_count":20726822,"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":["router","rxjava"],"created_at":"2024-07-31T21:00:20.952Z","updated_at":"2025-03-29T00:34:12.081Z","avatar_url":"https://github.com/ssseasonnn.png","language":"Kotlin","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"# RxRouter\n\n![](https://img.shields.io/badge/language-kotlin-brightgreen.svg) ![](https://img.shields.io/badge/RxJava-2.0-blue.svg) [![Download](https://api.bintray.com/packages/ssseasonnn/android/RxRouter/images/download.svg)](https://bintray.com/ssseasonnn/android/RxRouter/_latestVersion)\n\n\n*Read this in other languages: [中文](README.ch.md), [English](README.md)* \n\n一个轻量级、简单、智能并且强大的安卓路由库\n\n\n## Getting started\n\n### 添加依赖\n\n在build.gradle文件中添加以下依赖：\n\n```groovy\ndependencies {\n\timplementation 'zlc.season:rxrouter:x.y.z'\n\tannotationProcessor 'zlc.season:rxrouter-compiler:x.y.z'\n}\n```\n\n(替换上面的 `x` 、 `y` 和 `z`为最新的版本号:[![](https://api.bintray.com/packages/ssseasonnn/android/RxRouter/images/download.svg)](https://bintray.com/ssseasonnn/android/RxRouter/_latestVersion))\n\n如果使用 `Kotlin` ，用 `kapt` 替换 `annotationProcessor`\n\n### Hello World\n\n首先在我们需要路由的Activity上添加 `@Url` 注解：\n\n```kotlin\n@Url(\"this is a url\")\nclass UrlActivity : AppCompatActivity() {\n    ...\n}\n```\n\n然后创建一个被 `@Router` 注解的类，用来告诉RxRouter这里有一个路由器：\n\n```Kotlin\n@Router\nclass MainRouter{\n}\n```\n\n这个类不需要有任何其余的代码，RxRouter会根据这个类的类名自动生成一个 `RouterProvider` ，比如这里的 `MainRouter` 将会生成 `MainRouterProvider` .\n\n接着我们需要把这些路由器添加到 `RxRouterProviders` 中：\n\n```kotlin\nclass CustomApplication : Application() {\n    override fun onCreate() {\n        super.onCreate()\n        RxRouterProviders.add(MainRouterProvider())\n    }\n}\n```\n\n最后，就可以开始我们的表演了：\n\n```kotlin\nRxRouter.of(context)\n        .route(\"this is a uri\")\n        .subscribe()\n```\n\n### 参数传递\n\n携带参数跳转：\n\n通过with方法，你可以给本次路由添加一系列参数.\n\n```kotlin\nRxRouter.of(context)\n        .with(10)                         \t//int value\n        .with(true)\t\t\t\t\t\t\t//boolean value\n        .with(20.12)\t\t\t\t\t\t//double value\n        .with(\"this is a string value\")\t\t//string value\n        .with(Bundle())\t\t\t\t\t\t//Bundle value\n        .route(\"this is a uri\")\n        .subscribe()\n```\n\n\n\n### 不再需要 `onActivityResult` 方法了\n\n想要获取跳转返回的值？再也不用写一大堆 `onActivityResult` 方法了！链式调用，一步到位！\n\n```kotlin\nRxRouter.of(context)\n\t\t.with(false)\n        .with(2000)\n        .with(9999999999999999)\n        .route(\"this is a uri\")\n        .subscribe {\n            if (it.resultCode == Activity.RESULT_OK) {\n                val intent = it.data\n                val stringResult = intent.getStringExtra(\"result\")\n                result_text.text = stringResult\n                stringResult.toast()\n            }\n        }\n```\n\n如果有结果返回，在subscribe中处理就行了.\n\n\n\n### Class 跳转\n\n不想用Url注解？没问题，RxRouter同样支持原始的指定类名的跳转方式，和url跳转的方式相同：\n\n```kotlin\nRxRouter.of(context)\n        .routeClass(ClassForResultActivity::class.java)\n        .subscribe{\n            if (it.resultCode == Activity.RESULT_OK) {\n                val intent = it.data\n                val stringResult = intent.getStringExtra(\"result\")\n                result_text.text = stringResult\n                stringResult.toast()\n            }\n        }\n```\n\n\n\n### Action 跳转\n\n同样的，RxRouter也支持系统的Action和自定义的Action跳转.\n\n自定义Action跳转：\n\n```Xml\n\u003cactivity android:name=\".ActionActivity\"\u003e\n    \u003cintent-filter\u003e\n        \u003caction android:name=\"zlc.season.sample.action\" /\u003e\n        \u003ccategory android:name=\"android.intent.category.DEFAULT\" /\u003e\n    \u003c/intent-filter\u003e\n\u003c/activity\u003e\n```\n\n```kotlin\nRxRouter.of(context)\n        .routeAction(\"zlc.season.sample.action\")\n        .subscribe({\n            \"no result\".toast()\n        }, {\n            it.message?.toast()\n        })\n```\n\n系统Action跳转：\n\n```kotlin\n//拨打电话\nRxRouter.of(this)\n        .addUri(Uri.parse(\"tel:123456\"))\n        .routeSystemAction(Intent.ACTION_DIAL)\n        .subscribe()\n\n//发送短信\nval bundle = Bundle()\nbundle.putString(\"sms_body\", \"这是信息内容\")\nRxRouter.of(this)\n        .addUri(Uri.parse(\"smsto:10086\"))\n        .with(bundle)\n        .routeSystemAction(Intent.ACTION_SENDTO)\n        .subscribe()\n```\n\n\n\n### 防火墙\n\nRxRouter拥有一个小巧而强大的防火墙，能够在路由之前根据防火墙的规则进行拦截，您可以添加一个或者多个防火墙.\n\n```kotlin\n//创建一个LoginFirewall\nclass LoginFirewall : Firewall {\n    override fun allow(datagram: Datagram): Boolean {\n        if (notLogin) {\n            \"您还没有登录，请先登录\".toast()\n            return false\n        }\n        return true\n    }\n}\n\n//将Firewall添加到路由中\nRxRouter.of(this)\n        .addFirewall(LoginFirewall())\n        .route(\"this is a url\")\n        .subscribe()\n```\n\n\n### License\n\n\u003e ```\n\u003e Copyright 2018 Season.Zlc\n\u003e\n\u003e Licensed under the Apache License, Version 2.0 (the \"License\");\n\u003e you may not use this file except in compliance with the License.\n\u003e You may obtain a copy of the License at\n\u003e\n\u003e    http://www.apache.org/licenses/LICENSE-2.0\n\u003e\n\u003e Unless required by applicable law or agreed to in writing, software\n\u003e distributed under the License is distributed on an \"AS IS\" BASIS,\n\u003e WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\u003e See the License for the specific language governing permissions and\n\u003e limitations under the License.\n\u003e ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssseasonnn%2FRxRouter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fssseasonnn%2FRxRouter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssseasonnn%2FRxRouter/lists"}