路由方案對比:ARouter與WMRouter
文章來源自作者的Android進階計劃(ofollow,noindex">https://github.com/SusionSuc/AdvancedAndroid )
前面依次對這兩個路由框架做了原始碼分析,本文就來比較一下這兩個框架。這裡從兩個方面對比這兩個框架: 路由、模組間通訊
路由功能
WMRouter | ARouter | |
---|---|---|
多scheme和host的支援 | :white_check_mark:;可隨意新增,scheme、host不需要強制配置 | :negative_squared_cross_mark:;支援標準URL跳轉。有組的概念,一個路由(url)中的path必須屬於某個組 |
動態註冊路由節點 | :white_check_mark:;@RouterUri標註 | :white_check_mark:;@Route標註 |
URI正則匹配 | :white_check_mark:;使用@RouterRegex標註,匹配的path可以直接跳轉到對應介面,比如weblink的跳轉可以配置正則匹配來路由 | :negative_squared_cross_mark:;組的概念存在,不支援 |
攔截器 | :white_check_mark:;支援配置全域性攔截器和區域性攔截器,分別可配置多個,可以自定義攔截順序 | :white_check_mark:;支援配置全域性攔截器,可以自定義攔截順序 |
轉場動畫 | :white_check_mark:; | :white_check_mark:; |
降級策略 | :white_check_mark:;支援全域性降級和區域性降級 | :white_check_mark:;支援全域性降級和區域性降級 |
跳轉監聽 | :white_check_mark:;支援全域性和單次 | :white_check_mark:;支援全域性和單次 |
跳轉引數 | :white_check_mark:;支援基本型別和自定義型別 | :white_check_mark:;支援基本型別和自定義型別 |
引數自動注入 | :negative_squared_cross_mark:; | :white_check_mark:; @Autowired 註解的屬性可被自動注入 |
外部跳轉控制 | :white_check_mark:; 需要配置入口Acitity,支援的uri需要在Manifest中配置 | :white_check_mark:;需要配置入口Acitity,支援的uri需要在Manifest中配置 |
特殊頁面跳轉控制 | :white_check_mark:;“exported”註解屬性配置,特定頁面可以配置不允許跳轉 | :negative_squared_cross_mark:; |
自動生成路由文件 | :negative_squared_cross_mark:; | :white_check_mark:; |
路由節點的生成方式 | :white_check_mark:; 框架載入時載入全部路由節點到記憶體 | :white_check_mark:;按照組的劃分進行懶載入 |
路由節點擴充套件 | :white_check_mark:;擴充套件性高,可以通過一個Uri來不只做頁面的跳轉 | :white_check_mark:; 一般 |
模組間通訊
WMRouter | ARouter | |
---|---|---|
獲取特定介面的實現 | :white_check_mark:; @RouterService 註解配置,支援獲取介面的所有實現,或根據Key獲取特定實現 | :white_check_mark:; @Route 註解配置,支援根據Path獲取對應介面實現 |
更多特性
這裡只是按照自己的理解做了簡單對比,關於兩個框架更多特性可訪問官方連結:
水平有限,如果錯誤,歡迎指出。