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.libs
Next Pagectx.logger

#ctx.location

Current route location information, equivalent to the React Router location object. It is typically used in conjunction with ctx.router and ctx.route to read the current path, query string, hash, and state passed through the route.

#Use Cases

ScenarioDescription
JSBlock / JSFieldPerform conditional rendering or logic branching based on the current path, query parameters, or hash.
Linkage Rules / FlowEngineRead URL query parameters for linkage filtering, or determine the source based on location.state.
Post-navigation processingReceive data passed from the previous page via ctx.router.navigate using ctx.location.state on the target page.

Note: ctx.location is only available in RunJS environments with a routing context (e.g., JSBlock within a page, FlowEngine, etc.); it may be null in pure backend or non-routing contexts (e.g., Workflows).

#Type Definition

location: Location;

Location comes from react-router-dom, consistent with the return value of React Router's useLocation().

#Common Fields

FieldTypeDescription
pathnamestringThe current path, starting with / (e.g., /admin/users).
searchstringThe query string, starting with ? (e.g., ?page=1&status=active).
hashstringThe hash fragment, starting with # (e.g., #section-1).
stateanyArbitrary data passed via ctx.router.navigate(path, { state }), not reflected in the URL.
keystringA unique identifier for this location; the initial page is "default".

#Relationship with ctx.router and ctx.urlSearchParams

PurposeRecommended Usage
Read path, hash, statectx.location.pathname / ctx.location.hash / ctx.location.state
Read query parameters (as object)ctx.urlSearchParams, which provides the parsed object directly.
Parse search stringnew URLSearchParams(ctx.location.search) or use ctx.urlSearchParams directly.

ctx.urlSearchParams is parsed from ctx.location.search. If you only need query parameters, using ctx.urlSearchParams is more convenient.

#Examples

#Branching Based on Path

if (ctx.location.pathname.startsWith('/admin/users')) {
  ctx.message.info('Currently on the user management page');
}

#Parsing Query Parameters

// Method 1: Using ctx.urlSearchParams (Recommended)
const page = ctx.urlSearchParams.page || 1;
const status = ctx.urlSearchParams.status;

// Method 2: Using URLSearchParams to parse search
const params = new URLSearchParams(ctx.location.search);
const page = params.get('page') || '1';
const status = params.get('status');

#Receiving State Passed via Route Navigation

// When navigating from the previous page: ctx.router.navigate('/users/123', { state: { from: 'dashboard' } })
const prevState = ctx.location.state;
if (prevState?.from === 'dashboard') {
  ctx.message.info('Navigated from the dashboard');
}

#Locating Anchors via Hash

const hash = ctx.location.hash; // e.g., "#edit"
if (hash === '#edit') {
  // Scroll to the edit area or execute corresponding logic
}

#Related

  • ctx.router: Route navigation; the state from ctx.router.navigate can be retrieved via ctx.location.state on the target page.
  • ctx.route: Current route match information (parameters, configuration, etc.), often used in conjunction with ctx.location.