Top Related Projects
💪 A framework for assisting in the renovation of Android componentization (帮助 Android App 进行组件化改造的路由框架)
Kotlin/Native infrastructure
WMRouter是一款Android路由框架,基于组件化的设计思路,有功能灵活、使用简单的特点。
A simple, annotation-based library for making deep link handling better on Android
Epoxy is an Android library for building complex screens in a RecyclerView
Quick Overview
Router is a lightweight, flexible Android routing library that simplifies navigation between activities and fragments. It supports both URI-based and custom routing schemes, making it easy to implement deep linking and modular navigation in Android applications.
Pros
- Simple and intuitive API for defining and handling routes
- Supports both URI-based routing and custom routing schemes
- Lightweight with minimal impact on app size
- Allows for easy implementation of deep linking
Cons
- Limited documentation and examples compared to some other routing libraries
- May require additional setup for complex navigation scenarios
- Not as feature-rich as some more comprehensive navigation libraries
- Less active development and community support compared to official Android Navigation component
Code Examples
- Basic route definition and navigation:
// Define a route
Router.registerRouter("activity://main", MainActivity::class.java)
// Navigate to the defined route
Router.build("activity://main").go(context)
- Passing parameters through routing:
// Define a route with parameters
Router.registerRouter("user/:id", UserActivity::class.java)
// Navigate with parameters
Router.build("user/123")
.withString("name", "John Doe")
.go(context)
- Intercepting navigation:
Router.addGlobalInterceptor { context, uri, extras, callback ->
if (uri.toString().startsWith("https://")) {
// Handle external links
openInBrowser(context, uri)
callback.onInterrupt()
} else {
callback.onContinue()
}
}
Getting Started
- Add the dependency to your app's
build.gradle
:
dependencies {
implementation 'com.chenenyu.router:router:1.7.1'
}
- Initialize Router in your Application class:
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
Router.initialize(this)
}
}
- Define routes in your activities or fragments:
@Route("main")
class MainActivity : AppCompatActivity() {
// ...
}
- Use Router to navigate:
Router.build("main").go(context)
Competitor Comparisons
💪 A framework for assisting in the renovation of Android componentization (帮助 Android App 进行组件化改造的路由框架)
Pros of ARouter
- More comprehensive documentation and examples
- Supports advanced features like interceptors and dependency injection
- Backed by Alibaba, potentially offering better long-term support
Cons of ARouter
- Steeper learning curve due to more complex API
- Requires annotation processing, which may increase build times
- Heavier dependency compared to Router
Code Comparison
Router:
Router.build("user/1234").go(context)
ARouter:
ARouter.getInstance().build("/user/1234").navigation()
Summary
ARouter offers a more feature-rich solution with advanced capabilities, making it suitable for larger, complex projects. It provides better documentation and examples, which can be beneficial for teams. However, this comes at the cost of a steeper learning curve and potentially longer build times due to annotation processing.
Router, on the other hand, provides a simpler API and lighter dependency, making it easier to integrate and use in smaller projects. It may lack some advanced features but offers a more straightforward approach to navigation.
The choice between the two depends on the project's complexity, team size, and specific requirements. ARouter is better suited for large-scale applications with complex navigation needs, while Router may be preferable for simpler projects or those prioritizing ease of use and quick integration.
Kotlin/Native infrastructure
Pros of kotlin-native
- Enables Kotlin code compilation to native binaries for multiple platforms
- Provides interoperability with native languages like C and Objective-C
- Supports Kotlin multiplatform projects for sharing code across platforms
Cons of kotlin-native
- Steeper learning curve compared to Router's simplicity
- Requires more setup and configuration for native development
- May have larger binary sizes due to inclusion of Kotlin runtime
Code Comparison
Router:
Router.build("scheme://host/path").go(this);
kotlin-native:
@CName("kotlin_main")
fun main() {
println("Hello, Kotlin/Native!")
}
Router focuses on Android app navigation, while kotlin-native enables native development across platforms. Router provides a simple API for defining and handling routes within an Android app. In contrast, kotlin-native allows developers to write Kotlin code that can be compiled to native binaries for various platforms, including iOS, macOS, and Linux.
Router is more suitable for developers looking for an easy-to-use Android navigation solution, while kotlin-native is better suited for cross-platform native development projects that require deeper integration with platform-specific features and languages.
WMRouter是一款Android路由框架,基于组件化的设计思路,有功能灵活、使用简单的特点。
Pros of WMRouter
- More comprehensive documentation and examples
- Supports advanced features like interceptors and custom URI schemes
- Better integration with Android's navigation component
Cons of WMRouter
- Steeper learning curve due to more complex API
- Heavier dependency footprint
- May be overkill for simpler projects
Code Comparison
WMRouter:
@RouterUri("scheme://host/path")
public class SampleActivity extends Activity {
@Autowired
String param1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WMRouter.getInstance().inject(this);
}
}
Router:
@Route("scheme://host/path")
public class SampleActivity extends Activity {
@InjectParam
String param1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Router.injectParams(this);
}
}
Both libraries use annotations for route definitions and parameter injection. WMRouter uses @RouterUri
and @Autowired
, while Router uses @Route
and @InjectParam
. WMRouter requires calling WMRouter.getInstance().inject(this)
, whereas Router uses Router.injectParams(this)
for parameter injection.
WMRouter offers more advanced features and better integration with Android's navigation component, making it suitable for complex projects. However, Router provides a simpler API and lighter footprint, which may be preferable for smaller applications or those requiring basic routing functionality.
A simple, annotation-based library for making deep link handling better on Android
Pros of DeepLinkDispatch
- More robust and feature-rich, with support for complex deep linking scenarios
- Better documentation and community support, backed by Airbnb
- Annotation-based approach, which can lead to cleaner and more maintainable code
Cons of DeepLinkDispatch
- Steeper learning curve due to its more complex architecture
- Potentially higher overhead for simpler routing needs
- Requires more setup and configuration compared to Router
Code Comparison
Router:
Router.build("example://profile/123").go(context)
DeepLinkDispatch:
@DeepLink("example://profile/{id}")
public class ProfileActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String id = intent.getStringExtra("id");
}
}
Router offers a more straightforward approach for simple routing, while DeepLinkDispatch provides a more structured and annotation-based method for handling deep links. DeepLinkDispatch's approach may be more suitable for larger projects with complex routing requirements, while Router might be preferable for smaller projects or those with simpler routing needs.
Epoxy is an Android library for building complex screens in a RecyclerView
Pros of Epoxy
- More comprehensive UI building solution, offering advanced RecyclerView management and complex view hierarchies
- Robust data binding and state management capabilities
- Extensive documentation and community support due to Airbnb's backing
Cons of Epoxy
- Steeper learning curve due to its complexity and feature-rich nature
- Potentially overkill for simpler projects that don't require advanced UI management
- Larger library size and potential performance overhead for small apps
Code Comparison
Router:
@Route("activity://main")
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
Epoxy:
class MainController : EpoxyController() {
override fun buildModels() {
header {
id("header")
title("My App")
}
itemList.forEach { item ->
itemView {
id(item.id)
title(item.title)
}
}
}
}
Summary
Router focuses on simplifying Android navigation, while Epoxy provides a comprehensive solution for building complex, dynamic UIs. Router is lightweight and easy to integrate, making it suitable for projects primarily needing navigation support. Epoxy, on the other hand, offers powerful tools for managing RecyclerViews and complex view hierarchies, making it ideal for apps with sophisticated UI requirements.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Router
ä¸æwiki. æ¹ä¾¿çè¯ç»ä¸ªstar!â¤ï¸
Getting started
- Add router gradle plugin to your project-level
build.gradle
, as shown below.
buildscript {
repositories {
google()
mavenCentral()
// jcenter() // deprecated
}
dependencies {
classpath 'com.android.tools.build:gradle:+'
classpath "com.chenenyu.router:gradle-plugin:x.y.z"
}
}
latest router-gradle-plugin
version:
- Apply router plugin in your module-level 'build.gradle'.
apply plugin: 'com.android.application' // apply plugin: 'com.android.library'
apply plugin: 'com.chenenyu.router'
注æ: å¨rootProjectçbuild.gradle
æ件ä¸, å¯ä»¥æå®æ件å¼ç¨çlibraryçæ¬.
ext {
routerVersion = 'x.y.z'
compilerVersion = 'x.y.z'
compilerLoggable = true/false // æå¼/å
³éç¼è¯ælog
}
latest router
version:
latest compiler
version:
åºæ¬ç¨æ³
- æ·»å æ¦æªå¨(å¯é)
@Interceptor("SampleInterceptor")
public class SampleInterceptor implements RouteInterceptor {
@Override
public RouteResponse intercept(Chain chain) {
// do something
return chain.process();
}
}
- æ·»å 注解
// ç»Activityæ·»å 注解ï¼æå®äºè·¯å¾åæ¦æªå¨(å¯é)
@Route(value = "test", interceptors = "SampleInterceptor")
public class TestActivity extends AppCompatActivity {
@InjectParam(key="foo") // åæ°æ å°
String foo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Router.injectParams(this); // èªå¨ä»bundleä¸è·å并注å
¥åæ°
...
}
}
// ç»Fragmentæ·»å 注解
@Route("test")
public class TestFragment extends Fragment {
...
}
- 跳转
// ç®å跳转
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(RouteStatus status, Uri uri, String message) {
// do something
}
});
// è·åè·¯ç±å¯¹åºçintent
Router.build("test").getIntent();
// è·å注解çFragment
Router.build("test").getFragment();
è¿é¶ç¨æ³
建议æµè§ wiki.
讨论
QQ group: 271849001
Donate â¤ï¸
License
Top Related Projects
💪 A framework for assisting in the renovation of Android componentization (帮助 Android App 进行组件化改造的路由框架)
Kotlin/Native infrastructure
WMRouter是一款Android路由框架,基于组件化的设计思路,有功能灵活、使用简单的特点。
A simple, annotation-based library for making deep link handling better on Android
Epoxy is an Android library for building complex screens in a RecyclerView
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot