How to handle redirection with force:createRecord

There is an undocumented solution for this. Below is the js controller function that creates a new Contact record and redirects back from the record page to the initial page after a new record is created.

createNewContact: function(component, event, helper) {
    var windowHash = window.location.hash;
    var createEvent = $A.get("e.force:createRecord");
    createEvent.setParams({
        "entityApiName": "Contact",
        "panelOnDestroyCallback": function(event) {
            window.location.hash = windowHash;
        }
    });
    createEvent.fire();
}

Where "panelOnDestroyCallback" is the hidden force:createRecord attribute. I know that's an ugly hack, but hey, if I had known this before I wouldn't have spent 50+ hours implementing a fully-custom multi-object 'createRecord' component with all the schema tricks, custom lookups, multipicklists etc.


This is the standard designed behavior of force:create record. There is no way to handle the redirection on click of Save button. If you want to do that you have to prepare a custom component for that.