A router instance based on React Router, used for programmatic navigation within RunJS. It is typically used in conjunction with ctx.route and ctx.location.
| Scenario | Description |
|---|---|
| JSBlock / JSField | Navigate to detail pages, list pages, or external links after a button click. |
| Linkage Rules / Event Flow | Execute navigate to a list or detail page after successful submission, or pass state to the target page. |
| JSAction / Event Handling | Execute route navigation within logic such as form submissions or link clicks. |
| View Navigation | Update the URL via navigate during internal view stack switching. |
Note:
ctx.routeris only available in RunJS environments with a routing context (e.g., JSBlock within a page, Flow pages, event flows, etc.); it may be null in pure backend or non-routing contexts (e.g., Workflows).
Router is derived from @remix-run/router. In RunJS, navigation operations such as jumping, going back, and refreshing are implemented via ctx.router.navigate().
Navigates to a target path, or executes a back/refresh action.
Signature:
Parameters:
to: Target path (string), relative history position (number, e.g., -1 to go back), or null (to refresh the current page).options: Optional configuration.
replace?: boolean: Whether to replace the current history entry (default is false, which pushes a new entry).state?: any: State to pass to the target route. This data does not appear in the URL and can be accessed via ctx.location.state on the target page. It is suitable for sensitive information, temporary data, or information that should not be placed in the URL.| Purpose | Recommended Usage |
|---|---|
| Navigation/Jumping | ctx.router.navigate(path) |
| Read current path | ctx.route.pathname or ctx.location.pathname |
| Read state passed during navigation | ctx.location.state |
| Read route parameters | ctx.route.params |
ctx.router is responsible for "navigation actions," while ctx.route and ctx.location are responsible for the "current route state."
navigate(path) pushes a new history entry by default, allowing users to return via the browser's back button.replace: true replaces the current history entry without adding a new one, which is suitable for scenarios like post-login redirection or navigation after successful submission.state parameter:
state does not appear in the URL, making it suitable for sensitive or temporary data.ctx.location.state on the target page.state is saved in the browser history and remains accessible during forward/backward navigation.state will be lost after a hard page refresh.state is read here after navigation.