ctx.location
当前路由位置信息,与 React Router 的 location 对象等价。通常与 ctx.router、ctx.route 配合使用,用于读取当前路径、查询字符串、hash 以及通过路由传递的 state。
适用场景
注意:
ctx.location仅在存在路由上下文的 RunJS 环境中可用(如页面内的 JSBlock、事件流等);在纯后端或无路由的上下文(如工作流)中可能为空。
类型定义
Location 来自 react-router-dom,与 React Router 的 useLocation() 返回值一致。
常用字段
与 ctx.router、ctx.urlSearchParams 的关系
ctx.urlSearchParams 由 ctx.location.search 解析而来,若只需查询参数,使 用 ctx.urlSearchParams 更便捷。
示例
根据路径做分支
解析查询参数
接收路由跳转传递的 state
根据 hash 定位锚点
相关
- ctx.router:路由导航,
ctx.router.navigate的state在目标页可通过ctx.location.state获取 - ctx.route:当前路由匹配信息(参数、配置等),通常与
ctx.location配合使用

