Action: navigateBack
The navigateBack action allows users to navigate back to the previous screen within the app’s navigation stack. It removes the current screen from the navigation history, so when the user navigates back, the previous screen reappears. This action is also useful when working with modal screens, as it closes the modal and returns the user to the originating screen.
Properties
| Property | Type | Description |
|---|---|---|
| data | object | Data object to send back to the previous screen. This allows you to pass information back when navigating back. |
Example: Navigating Back
In this example, we use the navigateScreen action to navigate to another screen, and then use the navigateBack action to return to the originating screen. The data is used to send data back to the previous screen when navigating back.
Originating Screen
View:
styles:
scrollableView: true
body:
Column:
styles:
padding: 24
children:
- Button:
label: Go to demo screen
onTap:
navigateScreen:
name: navigateBack Demo
onNavigateBack:
showToast:
message: ${event.data}Target Screen
View:
styles:
scrollableView: true
body:
Column:
styles:
padding: 24
children:
- Button:
label: Go Back
onTap:
navigateBack:
data:
message: This is example of data passed when navigating back.
Explanation
-
Navigate to Another Screen:
First, the user clicks the "Go to demo screen" button, which triggers thenavigateScreenaction, navigating to a new screen callednavigateBack Demo.- Button: label: Go to demo screen onTap: navigateScreen: name: navigateBack Demo onNavigateBack: showToast: message: ${event.data} -
Trigger
navigateBackon the Target Screen:
On the demo screen, there’s a button with the label "Go Back." When this button is pressed, thenavigateBackaction is triggered, sending a data containing a message back to the previous screen:- Button: label: Go Back onTap: navigateBack: data: message: This is example of data passed when navigating back. -
Access the data on the Originating Screen:
When the user navigates back using thenavigateBackaction, theonNavigateBackevent is triggered on the source screen. This event gives you access to the data sent during thenavigateBackaction viaevent.data. You can then use this data to perform actions, such as displaying a message withshowToastor updating other UI elements on the source screen.- Button: label: Go to demo screen onTap: navigateScreen: name: navigateBack Demo onNavigateBack: showToast: message: ${event.data}
You can try complete example here (opens in a new tab)