[SalesForce] Redirect not working on Aura component embedded in a VF page

Redirect to a record or any other page not working for an aura component which is embedded in a VF page.
tried force:navigateToURL, but does not work as I get an error that says "object not defined" for e.force:navigateToURL.
tried the static URL redirect, this works, but the page opens in the iFrame where the VF page sits on the detail page of the record.

I was hoping to find a way to redirect to a record or any other page from the detail page on which the VF page is embedded to a new page on the browser.

Any ideas/suggestions?

I need it to work for the VF page embedded which is calling an aura component.

Best Answer

One way that will work is to add a "callback" attribute to the component definition. In that callback you can trigger a redirect.

Add this to your component:

<aura:attribute name="callback" type="String" description="Call this to communcate results to parent" access="global"/>

In your helper class you would call it like this:

var func = cmp.get('v.callback');
if (func){
  func(); //this has no params, but you can pass them if you like
}

Finally in your instantiation, define the callback:

$Lightning.use("c:AppContainer", function () {
      $Lightning.createComponent("c:App", {
        callback: function(){window.location = "http://www.somewhere.com";},
        otherattribute: "blah"
      }, elementId, function (cmp) {});
    });    

Oh and don't worry that the attribute definition is a string - the magic of Javascript takes care of that for you ;)