Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsJul 23, 2026·3 min de lecture

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.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
ARouter
Commande d'installation directe
npx -y tokrepo@latest install f99f09b5-86d7-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en 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

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires