Scripts2026年7月23日·1 分钟阅读

ARouter — Android Component Routing Framework by Alibaba

A middleware framework for assisted routing between Android components, supporting activity navigation, dependency injection, and interceptor chains in modularized apps.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
ARouter
直接安装命令
npx -y tokrepo@latest install f99f09b5-86d7-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

ARouter is an Android routing framework developed by Alibaba that replaces explicit Intent-based navigation with URL-style path routing. In large modularized Android applications, modules cannot directly reference each other's classes. ARouter solves this by providing a compile-time route table and a runtime navigation API that decouples module dependencies while supporting parameter passing, interceptors, and service discovery.

What ARouter Does

  • Routes between activities and fragments using URL-style path strings instead of explicit class references
  • Passes typed parameters (primitives, Parcelable, Serializable) through a fluent builder API
  • Supports interceptor chains for authentication checks, logging, or analytics before navigation
  • Provides dependency injection for cross-module service discovery without direct class coupling
  • Generates route tables at compile time via annotation processing for fast runtime lookups

Architecture Overview

ARouter uses annotation processing to scan @Route annotations at compile time and generate route-table classes mapping path strings to target components. At runtime, ARouter.init() loads these tables into a Warehouse registry. Navigation calls look up the target class by path, construct an Intent or Fragment instance, inject parameters, run any registered interceptors, and then perform the navigation. Service discovery follows a similar lookup pattern using IProvider interfaces.

Setup & Configuration

  • Add arouter-api and arouter-compiler dependencies to each module that declares routes
  • Call ARouter.init(application) in your Application class during startup
  • Annotate activities and fragments with @Route(path = "/group/name")
  • Use @Autowired annotations on fields to receive injected navigation parameters
  • Register global interceptors by implementing IInterceptor with a @Route annotation and priority value

Key Features

  • URL-style path routing that decouples navigation from compile-time class dependencies
  • Compile-time route table generation with no runtime reflection for route lookups
  • Interceptor chain support for cross-cutting concerns like login validation before navigation
  • Cross-module service discovery via IProvider interface for dependency injection patterns
  • Support for URI-based deep linking from external sources using the same route paths

Comparison with Similar Tools

  • Jetpack Navigation — Google's official navigation framework with NavGraph and SafeArgs; ARouter is more flexible for large modular projects without NavGraph XML
  • DeepLinkDispatch by Airbnb — annotation-based deep link handling; ARouter provides a broader feature set including interceptors and service discovery
  • TheRouter — newer routing framework with KSP support; ARouter has a larger community and longer track record
  • Explicit Intents — standard Android navigation; ARouter adds path-based decoupling essential for multi-module architectures
  • Fragment Factory — Jetpack pattern for Fragment creation; ARouter handles both Activity and Fragment routing with parameter injection

FAQ

Q: Does ARouter support Kotlin and KSP? A: ARouter works in Kotlin projects using kapt for annotation processing. KSP support is available in community forks and newer versions.

Q: How does it handle deep links from external URLs? A: Register route paths that match your deep link URL patterns. ARouter dispatches incoming URIs to the matching route with parameter extraction.

Q: Can I use ARouter with Jetpack Compose navigation? A: ARouter targets Activity and Fragment navigation in the View system. For Compose navigation, consider using it alongside Compose NavHost for hybrid apps.

Q: What happens if a route path is not found? A: ARouter supports a global degradation service (DegradeService) that handles unresolvable routes, allowing custom fallback behavior.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产