Top Related Projects
Quick Overview
WMRouter is an Android routing framework developed by Meituan. It provides a flexible and efficient way to handle navigation between different components in Android applications, supporting both URI-based and method-based routing.
Pros
- Supports both URI-based and method-based routing, offering flexibility in implementation
- Provides automatic route registration through annotations, reducing boilerplate code
- Offers advanced features like interceptors, filters, and page stack management
- Integrates well with existing Android development practices and frameworks
Cons
- Limited documentation in English, which may be challenging for non-Chinese speaking developers
- Steep learning curve for developers unfamiliar with advanced routing concepts
- May introduce additional complexity to smaller projects that don't require extensive routing capabilities
- Requires careful management of dependencies and configurations in larger projects
Code Examples
- Defining a route using annotations:
@RouterUri("scheme://host/path")
public class SampleActivity extends Activity {
// Activity implementation
}
- Navigating to a route:
Router.startUri(context, "scheme://host/path");
- Using method-based routing:
@RouterMethod("methodName")
public static void sampleMethod(Context context, @Param("key") String value) {
// Method implementation
}
- Invoking a method-based route:
Router.callMethod("methodName", context, "paramValue");
Getting Started
- Add WMRouter to your project's
build.gradle
:
dependencies {
implementation 'com.meituan.android.wmrouter:wmrouter:1.2.0'
}
- Initialize WMRouter in your Application class:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
WMRouter.init(this);
}
}
- Define routes using annotations and start using WMRouter in your activities and fragments.
Competitor Comparisons
💪 A framework for assisting in the renovation of Android componentization (帮助 Android App 进行组件化改造的路由框架)
Pros of ARouter
- More extensive documentation and examples
- Supports multiple modules and component-based architecture
- Offers advanced features like interceptors and service discovery
Cons of ARouter
- Steeper learning curve due to more complex API
- Heavier dependency and potentially larger APK size
- May require more configuration for simple routing scenarios
Code Comparison
WMRouter:
@RouterUri("http://page.example.com/detail")
public class DetailActivity extends Activity {
// Activity implementation
}
Router.startActivity(context, "http://page.example.com/detail");
ARouter:
@Route(path = "/test/activity")
public class DetailActivity extends Activity {
// Activity implementation
}
ARouter.getInstance().build("/test/activity").navigation();
Key Differences
- WMRouter uses URL-like syntax for routing, while ARouter uses path-based routing
- ARouter provides more flexibility in route configuration and parameter passing
- WMRouter has a simpler API for basic routing scenarios
- ARouter offers more advanced features for complex navigation requirements
Use Cases
- WMRouter: Suitable for projects with simpler routing needs or those preferring URL-like syntax
- ARouter: Ideal for large-scale, multi-module projects requiring advanced routing capabilities
Both libraries aim to simplify Android app navigation, but ARouter offers more features at the cost of increased complexity, while WMRouter provides a more straightforward approach for basic routing needs.
🍭灵活的组件化路由框架.
Pros of Router
- Simpler setup and configuration process
- Supports custom URL schemes for deep linking
- Lightweight and easy to integrate into existing projects
Cons of Router
- Less comprehensive documentation compared to WMRouter
- Fewer advanced features for complex routing scenarios
- Smaller community and less frequent updates
Code Comparison
Router:
@Route("user/:id")
public class UserActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String id = getIntent().getStringExtra("id");
}
}
WMRouter:
@RouterUri(path = "/user/{id}")
public class UserActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String id = getIntent().getStringExtra("id");
}
}
Both libraries use annotations for route definitions, but Router uses a simpler syntax with :
for parameters, while WMRouter uses curly braces {}
. WMRouter offers more advanced features and flexibility, but Router provides a more straightforward approach for basic routing needs. The choice between the two depends on the project's complexity and specific 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
WMRouteræ¯ä¸æ¬¾Androidè·¯ç±æ¡æ¶ï¼åºäºç»ä»¶åç设计æè·¯ï¼æåè½çµæ´»ã使ç¨ç®åçç¹ç¹ã
请注æï¼å 为JCenterä¸çº¿ï¼ä»1.2.1å¼å§ï¼Group ä» com.sankuai.waimai.router åæ´ä¸º io.github.meituan-dianpingã
åè½ç®ä»
WMRouter主è¦æä¾URIååãServiceLoader两大åè½ã
URIåååè½å¯ç¨äºå¤å·¥ç¨ä¹é´ç页é¢è·³è½¬ãå¨æä¸åURIé¾æ¥ç跳转çåºæ¯ï¼ç¹ç¹å¦ä¸ï¼
- æ¯æå¤schemeãhostãpath
- æ¯æURIæ£åå¹é
- 页é¢é ç½®æ¯æJava代ç å¨æ注åï¼æ注解é ç½®èªå¨æ³¨å
- æ¯æé ç½®å ¨å±åå±é¨æ¦æªå¨ï¼å¯å¨è·³è½¬åæ§è¡åæ¥/å¼æ¥æä½ï¼ä¾å¦å®ä½ãç»å½ç
- æ¯æå次跳转ç¹æ®æä½ï¼Intent设置Extra/Flagsã设置跳转å¨ç»ãèªå®ä¹StartActivityæä½ç
- æ¯æ页é¢Exportedæ§å¶ï¼ç¹å®é¡µé¢ä¸å 许å¤é¨è·³è½¬
- æ¯æé ç½®å ¨å±åå±é¨é级çç¥
- æ¯æé ç½®å次åå ¨å±è·³è½¬çå¬
- å®å ¨ç»ä»¶å设计ï¼æ ¸å¿ç»ä»¶åå¯æ©å±ãæéç»åï¼å®ç°çµæ´»å¼ºå¤§çåè½
åºäºSPI (Service Provider Interfaces) ç设计ææ³ï¼WMRouteræä¾äºServiceLoader模åï¼ç±»ä¼¼Javaä¸çjava.util.ServiceLoader
ï¼ä½åè½æ´å å®åãéè¿ServiceLoaderå¯ä»¥å¨ä¸ä¸ªAppçå¤ä¸ªæ¨¡åä¹é´éè¿æ¥å£è°ç¨ä»£ç ï¼å®ç°æ¨¡å解è¦ï¼ä¾¿äºå®ç°ç»ä»¶åã模åé´éä¿¡ï¼ä»¥ååä¾èµæ³¨å
¥ç±»ä¼¼çåè½çãå
¶ç¹ç¹å¦ä¸ï¼
- 使ç¨æ³¨è§£èªå¨é ç½®
- æ¯æè·åæ¥å£çææå®ç°ï¼ææ ¹æ®Keyè·åç¹å®å®ç°
- æ¯æè·åClassæè·åå®ä¾
- æ¯ææ åæé ãContextæé ï¼æèªå®ä¹FactoryãProvideræé
- æ¯æåä¾ç®¡ç
- æ¯ææ¹æ³è°ç¨
å ¶ä»ç¹æ§ï¼
- ä¼åçGradleæ件ï¼å¯¹ç¼è¯èæ¶å½±åè¾å°
- ç¼è¯æåè¿è¡æ¶é ç½®æ£æ¥ï¼é¿å é ç½®å²çªåé误
- å®åçè°è¯åè½ï¼å¸®å©åæ¶åç°é®é¢
éç¨åºæ¯
WMRouteréç¨ä½ä¸éäºä»¥ä¸åºæ¯ï¼
-
Native+H5æ··åå¼å模å¼ï¼éè¦è¿è¡é¡µé¢ä¹é´çäºç¸è·³è½¬ï¼æè¿è¡çµæ´»çè¿è¥è·³è½¬é¾æ¥ä¸åãå¯ä»¥å©ç¨WMRouterç»ä¸é¡µé¢è·³è½¬é»è¾ï¼æ ¹æ®ä¸åçåè®®ï¼HTTPãHTTPSãç¨äºNative页é¢çèªå®ä¹åè®®ï¼è·³è½¬å¯¹åºé¡µé¢ï¼ä¸å¨è·³è½¬è¿ç¨ä¸å¯ä»¥ä½¿ç¨UriInterceptor对跳转é¾æ¥è¿è¡ä¿®æ¹ï¼ä¾å¦è·³è½¬H5页é¢æ¶å¨URLä¸å åæ°ã
-
ç»ä¸ç®¡çæ¥èªAppå¤é¨çURI跳转ãæ¥èªAppå¤é¨çURI跳转ï¼å¦æ使ç¨AndroidåççManifesté ç½®ï¼ä¼ç´æ¥å¯å¨å¹é çActivityï¼èå¾å¤æ¶åå¸æå æ£å¸¸å¯å¨Appæå¼é¦é¡µï¼å®æ常è§åå§åæµç¨ï¼ä¾å¦ç»å½ãå®ä½çï¼åå跳转ç®æ 页é¢ãæ¤æ¶å¯ä»¥ä½¿ç¨ç»ä¸çActivityæ¥æ¶ææå¤é¨URI跳转ï¼å°é¦é¡µæ¶åç¨WMRouterå¯å¨ç®æ 页é¢ã
-
页é¢è·³è½¬æå¤æå¤æé»è¾çåºæ¯ãä¾å¦å¤ä¸ªé¡µé¢é½éè¦å ç»å½ãå å®ä½åæå 许æå¼ï¼å¦æ使ç¨å¸¸è§æ¹æ¡ï¼è¿äºé¡µé¢é½éè¦å¤çç¸åçä¸å¡é»è¾ï¼èå©ç¨WMRouterï¼åªéè¦å¼å好UriInterceptor并é ç½®å°å个页é¢å³å¯ã
-
å¤å·¥ç¨ãç»ä»¶åãå¹³å°åå¼åãå¤å·¥ç¨å¼åè¦æ±å个工ç¨ä¹é´è½äºç¸éä¿¡ï¼ä¹å¯è½éå°åå¤åApp类似ç代ç å¤ç¨ãä¾èµæ³¨å ¥ãç¼è¯çé®é¢ï¼è¿äºé®é¢é½å¯ä»¥å©ç¨WMRouterçURIåååServiceLoader模å解å³ã
-
对ä¸å¡åç¹éæ±è¾å¼ºçåºæ¯ã页é¢è·³è½¬ä½ä¸ºæ常è§çä¸å¡é»è¾ä¹ä¸ï¼å¸¸å¸¸éè¦åç¹ãç»æ¯ä¸ªé¡µé¢é 置好URIï¼ä½¿ç¨WMRouterç»ä¸è¿è¡é¡µé¢è·³è½¬ï¼å¹¶å¨å ¨å±çOnCompleteListenerä¸åç¹å³å¯ã
-
对Appå¯ç¨æ§è¦æ±è¾é«çåºæ¯ãä¸æ¹é¢ï¼å¯ä»¥å¯¹é¡µé¢è·³è½¬å¤±è´¥è¿è¡åç¹çæ§ä¸æ¥ï¼åæ¶åç°çº¿ä¸é®é¢ï¼å¦ä¸æ¹é¢ï¼é¡µé¢è·³è½¬æ¶å¯ä»¥æ§è¡å¤æé»è¾ï¼åç°å¼å¸¸ï¼ä¾å¦æå¡ç«¯å¼å¸¸ã客æ·ç«¯å´©æºçï¼åèªå¨æå¼é级åç页é¢ï¼ä¿è¯å ³é®åè½çæ£å¸¸å·¥ä½ï¼æç»ç¨æ·å好çæ示ã
-
页é¢A/Bæµè¯ãå¨æé ç½®çåºæ¯ãå¨WMRouteræä¾çæ¥å£åºç¡ä¸è¿è¡å°éå¼åé ç½®ï¼å°±å¯ä»¥å®ç°ï¼æ ¹æ®ä¸åçA/Bæµè¯çç¥è·³è½¬ä¸åç页é¢å®ç°ï¼æ ¹æ®ä¸åçéè¦å¨æä¸åä¸ç»è·¯ç±è¡¨ï¼ç¸åçURI跳转å°ä¸åçä¸ç»é¡µé¢ï¼å®ç°æ¹é¢å¯ä»¥èªå®ä¹UriInterceptorï¼å¯¹å¹é çURIè¿å301çUriResult使跳转éå®åï¼ã
设计ä¸ä½¿ç¨ææ¡£
åå±èæ¯
å ³äºWMRouterçåå±èæ¯åè¿ç¨ï¼å¯åèç¾å¢ææ¯å客 WMRouterï¼ç¾å¢å¤åAndroidå¼æºè·¯ç±æ¡æ¶ã
æ´æ°æ¥å¿
使ç¨äºWMRouterç项ç®
ç¾å¢å¤å |
ç¾å¢å¤åå家ç |
ç¾å¢ |
大ä¼ç¹è¯ |
欢è¿è¡¥å ï¼å¹¶å建PullRequestã
è´¡ç®è / Contributors â¨
æè°¢ææåä¸è´¡ç®ç人åï¼
- å¦æéæ¼åéè¦è¡¥å çï¼å¯æç § all-contributors ææ¡£èªè¡æ·»å ï¼å¹¶å建Pull Requestã
- åä¸è´¡ç®è å¯å 微信jzj2015ï¼è¿å ¥ WMRouter Contributors 微信群å¦ä¹ 交æµã
Top Related Projects
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