The Trailblazer Community in Slack is now in Open Beta—join and connect in real time. [Join us in Slack]
A flow screen component can control navigation programmatically by dispatching navigation events from the lightning/flowSupport module. You can advance to the next screen, go back, pause the flow, or finish it, and you can check which actions are available before firing an event.
Import navigation events from lightning/flowSupport.
| Event | Description |
|---|---|
FlowNavigationNextEvent | Advances to the next screen. If the current screen is the last one, use FlowNavigationFinishEvent. |
FlowNavigationBackEvent | Returns to the previous screen. |
FlowNavigationPauseEvent | Pauses the flow interview and saves its state for later resumption. |
FlowNavigationFinishEvent | Finishes the flow interview and triggers any configured post-flow behavior, such as a redirect URL. |
Not every navigation action is available on every screen. For example, the Back action isn’t available if the current screen is the first screen, and the Pause action is available only in flows where saving is enabled. Before you fire a navigation event, check whether the corresponding action is available.
Flow Builder passes a list of available actions to your component through the availableActions property. Declare it as an @api property in your component’s JavaScript file.
1// myComponent.js
2import { LightningElement, api } from "lwc";
3
4export default class MyComponent extends LightningElement {
5 @api availableActions = [];
6}The availableActions array contains string values for each action the current screen supports: "NEXT", "BACK", "PAUSE", "FINISH".
Use availableActions to show or hide navigation buttons and to guard navigation event dispatches.
1get canGoNext() {
2 return this.availableActions.find((action) => action === "NEXT");
3}
4
5get canGoBack() {
6 return this.availableActions.find((action) => action === "BACK");
7}Import the events you need, then dispatch them in event handlers.
1import { LightningElement, api } from "lwc";
2import {
3 FlowNavigationNextEvent,
4 FlowNavigationBackEvent,
5 FlowNavigationPauseEvent,
6 FlowNavigationFinishEvent,
7} from "lightning/flowSupport";
8
9export default class MyNavigationComponent extends LightningElement {
10 @api availableActions = [];
11
12 handleNext() {
13 if (this.availableActions.find((action) => action === "NEXT")) {
14 this.dispatchEvent(new FlowNavigationNextEvent());
15 }
16 }
17
18 handleBack() {
19 if (this.availableActions.find((action) => action === "BACK")) {
20 this.dispatchEvent(new FlowNavigationBackEvent());
21 }
22 }
23
24 handlePause() {
25 if (this.availableActions.find((action) => action === "PAUSE")) {
26 this.dispatchEvent(new FlowNavigationPauseEvent());
27 }
28 }
29
30 handleFinish() {
31 if (this.availableActions.find((action) => action === "FINISH")) {
32 this.dispatchEvent(new FlowNavigationFinishEvent());
33 }
34 }
35}When your component provides its own navigation buttons, hide the flow screen’s built-in footer so that the screen has only one set of navigation controls. In Flow Builder, open the screen element that contains your component. In the Configure Footer section, disable Show Footer.
Follow these guidelines when using navigation events.
connectedCallback or renderedCallback.FlowAttributeChangeEvent and a navigation event at the same time. There’s no guarantee that the component has rendered updated values before navigation begins, which can cause race conditions.To improve flow performance, consider these best practices.
FlowNavigationNextEvent. Navigation moves the user away from the current screen immediately, so any code after the dispatch doesn’t run.If you encounter a scenario where navigation must be done within the initialization phase of the screen because data isn’t yet available to Flow Decision Nodes, post a request for an upgrade in Idea Exchange.
See Also