https://github.com/ma-jian/router
Activity Result API 方式启动的路由管理器、支持拦截、排序、自定义返回逻辑,多模块获取实例
https://github.com/ma-jian/router
kapt kotlin ksp provider router serviceloader
Last synced: 5 months ago
JSON representation
Activity Result API 方式启动的路由管理器、支持拦截、排序、自定义返回逻辑,多模块获取实例
- Host: GitHub
- URL: https://github.com/ma-jian/router
- Owner: ma-jian
- License: apache-2.0
- Created: 2023-05-19T06:22:33.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-07-16T07:58:18.000Z (11 months ago)
- Last Synced: 2025-07-17T10:56:14.452Z (11 months ago)
- Topics: kapt, kotlin, ksp, provider, router, serviceloader
- Language: Kotlin
- Homepage:
- Size: 340 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# router
Activity Result API 方式启动的路由管理器
```groovy
implementation 'io.github.ma-jian:router-api:1.1.0'
// kapt处理
kapt 'io.github.ma-jian:router-compiler:1.1.0'
// or ksp kt代码优先使用ksp方式提升编译速度
plugins {
id 'com.google.devtools.ksp'
}
ksp 'io.github.ma-jian:router-ksp:1.1.0'
```
### **CHANGELOG**
#### v1.1.0
1. 新增降级策略
2. 新增错误处理
3. 优化代码
#### v1.0.5
1. 修改@Autowired 字段为必填时的错误提示
2. 修改其他bug
#### v1.0.3
1. 新增注解[RouterInterceptor](router-annotation/src/main/java/com/mm/router/annotation/RouterInterceptor.kt) 路由拦截器,支持路由的自定义拦截
和路由拦截回调
2. 新增 ksp 注解处理逻辑,原生生成kotlin代码提升编译速度
3. 修改注解[ServiceProvider](router-annotation/src/main/java/com/mm/router/annotation/ServiceProvider.kt)处理逻辑,移除接口必须继承 IProvider 的限制
4. 修改其他bug
#### v1.0
1. [RouterPath](router-annotation/src/main/java/com/mm/router/annotation/RouterPath.kt) 路由地址注册页面路径
2. [ServiceProvider](router-annotation/src/main/java/com/mm/router/annotation/ServiceProvider.kt) 提供对外接口能力
3. [Autowired](router-annotation/src/main/java/com/mm/router/annotation/Autowired.kt) 对标记字段自动赋值,需要在赋值页面注册
Router.init(this).autoWired(this)
路由启动页面
startActivity
```kotlin
Router.init(this).open("com.mm.second").navigation()
```
startActivityForResult
```kotlin
Router.init().open(Router.Path.ACTION_CONTENT).navigation() {
if (it.resultCode == RESULT_OK) {
textView.text = textView.text.toString() + "\n ${it.data}"
}
}
```
路由降级策略
```kotlin
Router.enableFallback = true
Router.defaultFallback (object : FallbackHandler {
override fun handleFallback(path: String, bundle: Bundle?) {
Router.init().open("com.mm.second").withBundle(bundle).navigation()
}
})
```
获取拦截器结果
```kotlin
Router.init().open("/user/mine").navigationResult {
//路由执行完毕并返回信息
it.onSuccess { result ->
}
//路由被中断、通过在[Interceptor]中执行chain.interrupt()方法
it.onIntercepted {
}
//路由执行失败,返回值:true执行当前降级逻辑,false执行默认降级逻辑
it.onFailure {
false
}
}
```
两种获取接口的方式
@RouterPath 该方式获取Service 接口必须继承[IProvider](router-api/src/main/java/com/mm/router/IProvider.kt)
```kotlin
@RouterPath(value = "/router/service/autowired", des = "自动注册赋值")
class AutowiredServiceImpl : AutowiredService {
//...
}
val autowiredService = Router.init(this).open("/router/service/autowired").doProvider()
```
@ServiceProvider 该方式无需接口继承IProvider,但必须是接口实现类
```kotlin
/**
* 标记对外接口
*/
@ServiceProvider("/service/provider")
class ServiceProviderImpl (
private val string: String,
private val int: Int,
private val log: Long,
private val bol: Boolean
) : IServiceProvider {
//...
}
//获取接口实例
val provider = Router.init().open("/service/provider").doProvider("",1,2L,false)
```
@RouterInterceptor
```kotlin
@RouterInterceptor("/router/path/match", priority = 1, des = "路由拦截器")
class PathInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain, intent: Intent) {
}
}
```