In UI Builder, a client script moves a user to another page with helpers.navigate.to, not with a method on the api object. The call takes a route name from the UX App Routes table, plus optional fields, params, redirect, passiveNavigation and targetRoute values. It runs from a page script rather than from a scripted property value.
Why navigation sits under helpers and not api
The api object handles client state, events, read-only context such as the current user, and data resource calls. Moving the user to a new screen is a different kind of action, so it sits on the helpers object. There is no navigate function on api to call.
Where a navigation call can run
The helpers object is available to page scripts. It is not available in component property value scripts, component visibility scripts, event payload scripts or UX client script includes.
Page scripts receive api, event, helpers and imports. They can be written as asynchronous functions and can call api.emit, api.setState and the api.data methods. Scripted property values cannot be asynchronous and cannot make those side-effect calls.
| Capability | Page script | Scripted property value, visibility or event payload script |
|---|---|---|
| Uses the helpers object | Yes | No |
| Written as an asynchronous function | Yes | No |
| Calls api.emit, api.setState or api.data methods | Yes | No |
Put the navigation call in a page script bound to a component event, such as a button click.
The six arguments of helpers.navigate.to
The method signature is helpers.navigate.to(route, fields, params, redirect, passiveNavigation, targetRoute). Passing the route alone is enough for a basic move. The remaining arguments control the URL, the browser history and how the new page loads.
| Argument | Type | Default | What it controls |
|---|---|---|---|
| route | String | None (required) | The route name. It must be an entry in the UX App Routes table. |
| fields | Object | None (optional) | Key-value pairs for the required parameters of the route, such as a table name and a record identifier. |
| params | Object | None (optional) | Key-value pairs for the optional parameters of the route, such as a selected tab index. |
| redirect | Boolean | false | Whether the latest browser history entry is removed. |
| passiveNavigation | Boolean | false | Whether the new page loads in the background without being shown. |
| targetRoute | String or Object | Not stated | Sub-navigation under the current URL, such as a drill-down or sub-tab. |
How the route, fields and params form the URL
The URL takes the form of the route, then one value for each required field, then the word params followed by each optional key and its value. With the route record, fields for table incident and sysId 12345, and params with selectedTabIndex set to 4, the address is /record/incident/12345/params/selectedTabIndex/4.
Required parameters are the key-value pairs passed in fields, such as a table name and a record sys_id. Optional parameters are the key-value pairs passed in params, such as selectedTabIndex. For setRouteParams, a key that is not an optional parameter of the route is ignored, so check the route’s parameter list when a value is missing from the address.
Controlling browser history with redirect
The redirect argument controls what the back button shows after the move. It defaults to false, which removes no history entries.
When redirect is true, the latest history entry is removed and the browser moves to the new URL. Take a sequence of three screens, A, B and then C. If the move to C sets redirect to true, the history keeps A and C and drops B. The middle screen is no longer on the back-button path.
Judgment rather than a fixed rule: redirect true suits a step the user has no reason to return to, such as a loading step that passes straight through to the destination. Leave redirect at false when the user needs to step back through each screen they visited.
Loading a page in the background with passiveNavigation
The passiveNavigation argument also defaults to false. When it is true, the new page loads in the background, neither active nor shown. A typical example is an inactive tab that loads its content before the user switches to it.
Use this flag when the destination should be ready before the user reaches it. Leave it at false for a normal move.
Opening a screen inside the current one with targetRoute
The targetRoute argument covers sub-navigation to a drill-down, a deep link or a sub-tab. A string value of current runs a sub-navigation under the current URL, so the new route is appended beneath it. The object form takes a NAV_ITEM_SELECTED navigation payload instead.
Take a user on the record view for incident 123. A call with the route record, fields for table problem and sysId 567, empty params, false for redirect and passiveNavigation, and current for targetRoute produces the address /record/incident/123/sub/record/problem/567.
Use this when the new view belongs inside the current one. Use a plain move when the new screen replaces the current one.
Passing parameter values with setRouteParams
The helpers object also has helpers.navigate.setRouteParams, which does a different job. It does not move the user. It passes parameter values to other components on the same page and writes them into the URL. The usual case is a tab control, where the selected index is written into the URL.
The example passes the selected tab index with the value 2 inside a params object. The camelCase key selectedTabIndex appears in the URL as selected-tab-index, so the address gains the segment params/selected-tab-index/2.
The params object for this method has three rules:
- It must be a plain, flat object.
- Its values must be primitive. Arrays and object references are ignored and not added to the URL.
- Its keys must match optional parameters defined in the route configuration. Keys that do not match are ignored.
Reading and writing client state alongside navigation
A common use is to track values that a user enters into several form controls on one page, so a later script can read all of them. Declare each client state parameter from Data and scripts: point to Client state parameters and select the Add new (plus) icon, then give it a name, a type of String, Number, Boolean or JSON, and an initial value.
Use api.setState to change a value. It takes the parameter name and either the new value or a callback. Calls run asynchronously and do not necessarily update the screen straight away. When the new value depends on the current one, use the callback form. The callback receives currentValue and api, and it returns the new value. It should never mutate currentValue or api directly. Return a new value instead. For an object-valued parameter, return a new object that spreads currentValue and then sets the changed key.
To read a value, use api.state followed by the parameter name. The value is read-only, and nested object values cannot be mutated from scripts, so write a new object through api.setState instead.
Events are the other piece. api.emit sends a named event with a payload. Event names are written in upper snake case and in the past tense, such as ITEM_CHANGED or USER_SELECTED. The event name must be among the events dispatched by the page definition, which is part of the page definition. An api.emit call for an event that is not declared is ignored.
Wiring a navigation script to a button
The steps are:
- Open the experience, then open or create the page.
- Select the plus control next to Client scripts, and give the script a descriptive name.
- Write the script.
- Select the button on the page stage, then select the Events tab.
- Select + Add event handler, select the script that you created under Scripts, and then select Add.
- Select Save, then use the preview control to test the move.
Common mistakes with navigation calls
- Using a route name that is not an entry in the UX App Routes table.
- Passing a setRouteParams key that is not an optional parameter of the route. The key is ignored.
- Passing an array or nested object to setRouteParams. Those values are ignored.
- Emitting an event that the page definition does not declare. The call is ignored.
Frequently asked questions
Is there an api.navigate method in UI Builder?
No. Navigation lives on the helpers object as helpers.navigate.to. A script that moves the user should call the helpers method.
Where can I call helpers.navigate.to?
In a page script. The helpers object is not available in component property value scripts, component visibility scripts, event payload scripts or UX client script includes.
What does setting redirect to true change in the browser history?
It removes the latest history entry and sends the browser to the new URL. In a sequence from A to B to C, a redirect of true on the move to C leaves A and C in the history.
Why does a parameter I passed to setRouteParams not show up in the URL?
Usually because the key is not an optional parameter of the route, or because the value is an array or nested object. Both are ignored. Check the route’s parameter definition and make sure each value is a primitive.