You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jetpack Compose导航Deep Links:uriPattern如何匹配前缀URL?

要让Compose Navigation拦截所有以https://www.example.com为前缀的URL,你需要使用https://www.example.com/{*}作为uriPattern的值。

Compose Navigation的Deep Link采用URI模板语法,其中{*}是通配符占位符,表示匹配任意长度的路径内容(包括多级子路径),正好满足你匹配所有前缀URL的需求。之前尝试的**并不是官方支持的通配符格式,所以无法生效。

举个实际使用的代码示例:

// 在你的导航图中配置
navController.createGraph(startDestination = "home") {
    composable(
        route = "example_route",
        deepLinks = listOf(
            navDeepLink {
                uriPattern = "https://www.example.com/{*}"
            }
        )
    ) {
        // 这里放置需要拦截该Deep Link的可组合项
        ExampleScreen()
    }
}

这个配置会匹配所有符合以下规则的URL:

  • https://www.example.com(精确匹配)
  • https://www.example.com/abc
  • https://www.example.com/a/b/c
  • 任何以https://www.example.com/开头的多级路径URL

内容的提问来源于stack exchange,提问作者Arpit Shukla

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.27 04:53:17