TheRouter

object TheRouter

Functions

addActionInterceptor
链接已复制到剪贴板
fun addActionInterceptor(action: String?, interceptor: ActionInterceptor?)

新增 Action 拦截器

addAutowiredParser
链接已复制到剪贴板
fun addAutowiredParser(parser: AutowiredParser)

新增 @Autowired 注解解析器

build
链接已复制到剪贴板
fun build(it: Intent): Navigator

通过Intent构建路由导航器

fun build(url: String?): Navigator

通过Path构建路由导航器

get
链接已复制到剪贴板
fun <T> get(clazz: Class<T>, vararg params: Any?): T?

获取跨模块依赖的服务

init
链接已复制到剪贴板
fun init(context: Context?)

TheRouter初始化方法。内部流程:
同步流程:
1. 首先初始化FlowTask的内置事件,BEFORE_THEROUTER_INITIALIZATION,以及依赖这个Task的全部任务。 这个事件的目的是在TheRouter的路由初始化前做某些操作,例如修改路由表、添加路由拦截器等…… 2. 初始化跨模块依赖表 3. 初始化路由表 异步流程:
1. 调用FlowTask的外部事件 2. 添加 @Autowired 路由解析器

fun init(context: Context?, asyncInitRouterInject: Boolean)
inject
链接已复制到剪贴板
fun inject(any: Any?)

为 @Autowired 注解的变量赋值

isRouterAction
链接已复制到剪贴板
fun isRouterAction(url: String?): Boolean

判断 url 是否为 TheRouter 的 Action Path 会被记录到路由表内,Action不会被记录,Action更像是一个消息事件,参考Android的广播

isRouterPath
链接已复制到剪贴板
fun isRouterPath(url: String?): Boolean

判断 url 是否为 TheRouter 的路由 Path Path 会被记录到路由表内,Action不会被记录,Action更像是一个消息事件,参考Android的广播

removeActionInterceptor
链接已复制到剪贴板
fun removeActionInterceptor(action: String?, interceptor: ActionInterceptor?)

删除 Action 拦截器

removeAllInterceptorForKey
链接已复制到剪贴板
fun removeAllInterceptorForKey(action: String?): MutableList<ActionInterceptor?>

移除所有action对应的拦截器,如果action有多个拦截器,则都会被移除

removeAllInterceptorForValue
链接已复制到剪贴板
fun removeAllInterceptorForValue(interceptor: ActionInterceptor?)

移除所有指定拦截器,如果有多个action共用同一个拦截器,则都会被移除

runTask
链接已复制到剪贴板
fun runTask(taskName: String)

执行业务自定义的 FlowTask,仅支持自定义业务节点的 Task

Properties

digraph
链接已复制到剪贴板
val digraph: Digraph
isDebug
链接已复制到剪贴板
var isDebug: Boolean = false
logCat
链接已复制到剪贴板
var logCat: (tag: String, msg: String) -> Unit?

自定义log输出方式,例如可将某些指定Tag上报到服务端,仅Release包有效,Debug包永远输出在控制台

parserList
链接已复制到剪贴板
val parserList: LinkedList<AutowiredParser>
routerInject
链接已复制到剪贴板
val routerInject: RouterInject