0

I'm implementing a redirect in a Lightning component, but it's opening in a new browser tab. I want the redirect to happen in the same tab:

navigate : function(component, event, helper) {
 var urlEvent = $A.get("e.force:navigateToURL");
  urlEvent.setParams({
    'url': 'http://www.myurl.com'
  });
  urlEvent.fire();
}

Is there a way to force it to redirect in the same browser tab?

  • 1
    No it does not work.....you may need to use window.location... – Ayub Sep 5 '18 at 15:36
1

While using e.force:navigateToURL event, to be able to remain in the same window/tab, you need to use relative URL. If you use an absolute or external URL (as in your case), by default the event opens up a new window/tab and that there's no way to control that behavior.

Below is the excerpt where this behavior is mentioned in the event's documentation:

Relative and absolute URLs are supported. Relative URLs are relative to the Salesforce mobile web domain, and retain navigation history. External URLs open in a separate browser window.

If you refer to the example in the documentation, the first approach navigates to an Opportunity tab within the same window, whereas the second example opens the link in a new tab/window.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.