建议浏览中文wiki. It's better than you think.
- 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:版本号'
}
- 初始化
Router.initialize(new Configuration.Builder()
// 调试模式,开启后会打印log
.setDebuggable(BuildConfig.DEBUG)
// 模块名,每个使用Router的module都要在这里注册
.registerModules("your app module", "your lib module", "other module")
.build());
- 添加注解
// 这里添加了path和拦截器
@Route(value = "test", interceptors = "SampleInterceptor")
public class TestActivity extends AppCompatActivity {
...
}
- 添加拦截器
@Interceptor("SampleInterceptor")
public class SampleInterceptor implements RouteInterceptor {
@Override
public boolean intercept(Context context, RouteRequest routeRequest) {
// do something
return false;
}
}
- 跳转
// 简单跳转
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.
See wiki.
QQ group: 271849001