---
schema_version: "1"
id: 6c683082d9956f083debb7605dead5e513b06f8b6bfa1035ff7835432e739a5b
title: Control a Flow’s Finish Behavior by Wrapping the Flow in a Custom Aura Component
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/aura-platform/guides/aura/components/components-using-flow-onfinish.md
canonical_url: https://developer.salesforce.com/docs/platform/aura-platform/guide/components-using-flow-onfinish.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: e1370b2da4fb1712f7292b9c7c88c79b3ac547f55da268f35fe4f51dad5a8431
products:
  - Lightning Aura Components Developer Guide
  - Platform Developer Content
---

# Control a Flow’s Finish Behavior by Wrapping the Flow in a Custom Aura Component

By default, when a flow user clicks **Finish**, a new interview starts and the user sees the first screen of the flow again. By embedding a flow in a custom Aura component, you can shape what happens when the flow finishes by using the `onstatuschange` action. To redirect to another page, use one of the `force:navigateTo`\* events such as `force:navigateToObjectHome` or `force:navigateToUrl`.

**tip:** To control a flow’s finish behavior at design time, make your custom Aura component available as a flow action by using the `lightning:availableForFlowActions` interface. To control what happens when an autolaunched flow finishes, check for the `FINISHED_SCREEN` status.

```nolang
<aura:component access="global">
    <aura:handler name="init" value="{!this}" action="{!c.init}" />
    <lightning:flow aura:id="flowData" onstatuschange="{!c.handleStatusChange}" />
</aura:component>
```

```javascript
// init function here
handleStatusChange : function (component, event) {
   if(event.getParam("status") === "FINISHED") {
        // Redirect to another page in Salesforce, or
        // Redirect to a page outside of Salesforce, or
        // Show a toast, or...
    }
}
```

In this example, the function redirects the user to a case created in the flow by using the `force:navigateToSObject` event.

```javascript
handleStatusChange : function (component, event) {
   if(event.getParam("status") === "FINISHED") {
      var outputVariables = event.getParam("outputVariables");
      var outputVar;
      for(var i = 0; i < outputVariables.length; i++) {
         outputVar = outputVariables[i];
         if(outputVar.name === "redirect") {
            var urlEvent = $A.get("e.force:navigateToSObject");
            urlEvent.setParams({
               "recordId": outputVar.value,
               "isredirect": "true"
            });
            urlEvent.fire();
         }
      }
   }
}
```

**See Also**

- [_Component Library_: lightning:flow Component](https://developer.salesforce.com/docs/component-library/bundle/lightning:flow/documentation)

- [Create Flow Local Actions Using Aura Components](https://developer.salesforce.com/docs/platform/aura-platform/guide/components-config-for-flow-actions.md)
