Router

项目地址:chenenyu/Router
简介:🚀🚀🚀Simple and flexible router library for Android platform.
更多:作者   æ Bug   
标签:

Build Status license PullRequest

建议浏览中文 wiki. It's better than you think.

screenshot

Getting started

  • Add dependencies by adding the following lines to your build.gradle:
android {
    defaultConfig {
        ...
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["moduleName": project.name]
            }
        }
    }
}

dependencies {
    implementation 'com.chenenyu.router:router:版本号'
    annotationProcessor 'com.chenenyu.router:compiler:版本号'
}

latest router version: Download

latest compiler version: compiler

基本用法

  1. 初始化
Router.initialize(new Configuration.Builder()
        // 调试模式,开启后会打印 log
        .setDebuggable(BuildConfig.DEBUG)
        // 模块名,每个使用 Router 的 module 都要在这里注册
        .registerModules("your app module", "your lib module", "other module")
        .build());
  1. 添加注解
// 这里添加了 path 和拦截器
@Route(value = "test", interceptors = "SampleInterceptor")
public class TestActivity extends AppCompatActivity {
    ...
}
  1. 添加拦截器
@Interceptor("SampleInterceptor")
public class SampleInterceptor implements RouteInterceptor {
    @Override
    public boolean intercept(Context context, RouteRequest routeRequest) {
        // do something
        return false;
    }
}
  1. 跳转
// 简单跳转
Router.build("test").go(this);
// startActivityForResult
Router.build("test").requestCode(0).go(this);
// 携带 bundle 参数
Router.build("test").with("key", Object).go(this);
// 添加回调
Router.build("test").go(this, new RouteCallback() {
        @Override
        public void callback(RouteResult state, Uri uri, String message) {
             // do something
        }
});

进阶用法

Please refer to the wiki for more informations.

ProGuard

See wiki.

讨论

QQ group: 271849001

License

Apache 2.0

随手点击下面广告,支持我维护本站吧
随手点击下面广告支持我免费维护吧
Android 开发经验分享
随手点击下面广告支持本站吧
 
Android 开发经验分享