logologo
Get Started
Tutorials
Guide
Development
Plugins
API
Home
English
简体中文
日本語
한국어
Español
Português
Deutsch
Français
Русский
Get Started
Tutorials
Guide
Development
Plugins
API
Home
logologo
RunJS Overview
Importing Modules
Rendering in Container

Global Variables

window
document
navigator

ctx

ctx.blockModel
ctx.collection
ctx.collectionField
ctx.dataSource
ctx.dataSourceManager
ctx.element
ctx.exit()
ctx.exitAll()
ctx.filterManager
ctx.form
ctx.getModel()
ctx.getValue()
ctx.getVar()
ctx.i18n
ctx.importAsync()
ctx.initResource()
ctx.libs
ctx.location
ctx.logger
ctx.makeResource()
ctx.message
ctx.modal
ctx.model
ctx.notification
ctx.off()
ctx.on()
ctx.openView()
ctx.render()
ctx.request()
ctx.requireAsync()
ctx.resource
ctx.route
ctx.router
ctx.setValue()
ctx.sql
ctx.t()
ctx.view
Previous Pagectx.resource
Next Pagectx.router

#ctx.route

The current route matching information, corresponding to the route concept in React Router. It is used to retrieve the current matching route configuration, parameters, and more. It is typically used in conjunction with ctx.router and ctx.location.

#Use Cases

ScenarioDescription
JSBlock / JSFieldPerform conditional rendering or display the current page identifier based on route.pathname or route.params.
Linkage Rules / FlowEngineRead route parameters (e.g., params.name) for logic branching or to pass them to child components.
View NavigationInternally compare ctx.route.pathname with a target path to determine whether to trigger ctx.router.navigate.

Note: ctx.route is only available in RunJS environments that contain a routing context (such as JSBlocks within a page, Flow pages, etc.). It may be null in pure backend or non-routing contexts (such as background workflows).

#Type Definition

type RouteOptions = {
  name?: string;   // Unique route identifier
  path?: string;   // Route template (e.g., /admin/:name)
  params?: Record<string, any>;  // Route parameters (e.g., { name: 'users' })
  pathname?: string;  // Full path of the current route (e.g., /admin/users)
};

#Common Fields

FieldTypeDescription
pathnamestringThe full path of the current route, consistent with ctx.location.pathname.
paramsRecord<string, any>Dynamic parameters parsed from the route template, such as { name: 'users' }.
pathstringThe route template, such as /admin/:name.
namestringUnique route identifier, commonly used in multi-tab or multi-view scenarios.

#Relationship with ctx.router and ctx.location

PurposeRecommended Usage
Read current pathctx.route.pathname or ctx.location.pathname; both are consistent during matching.
Read route parametersctx.route.params, e.g., params.name representing the current page UID.
Navigationctx.router.navigate(path)
Read query parameters, statectx.location.search, ctx.location.state

ctx.route focuses on the "matched route configuration," while ctx.location focuses on the "current URL location." Together, they provide a complete description of the current routing state.

#Examples

#Reading pathname

// Display the current path
ctx.message.info('Current Page: ' + ctx.route.pathname);

#Branching based on params

// params.name is typically the current page UID (e.g., a Flow page identifier)
if (ctx.route.params?.name === 'users') {
  // Execute specific logic on the user management page
}

#Displaying in a Flow page

<div>
  <h1>Current Page - {ctx.route.pathname}</h1>
  <p>Route Identifier: {ctx.route.params?.name}</p>
</div>

#Related

  • ctx.router: Route navigation. When ctx.router.navigate() changes the path, ctx.route will update accordingly.
  • ctx.location: Current URL location (pathname, search, hash, state), used in conjunction with ctx.route.