When I try to redirect users using force:navigateToURL and i specify a redirecturi which is within my community, it seems to ignore the external reference, and treat it as a community page. For Example:

var urlEvent = $A.get("e.force:navigateToURL");
          "url": 'https://www.3rdPartyWebSite.ca/potato?

I am redirected to :


since this page doesnt exist, well, the user is not redirected anywhere. threfore I am forced to use window.open('url').

Is there a way to properly handle the redirection using force:navigateToURL?

FYI: note that to reproduce, you must replace MyCommunityUrl with "Your community Url"

| improve this question | | | | |

It looks like the component does not handle several scenarios for already logged in users when adding community Urls as redirect parameters.

I thought that maybe encoding the url would have solved the Issue:

var encodedUrl = encodeURIComponent(url);

However, the underlying issue remains. The only working scenario was by encoding the redirect_uri parameter

    var url = 'https://www.3rdPartyWebSite.ca/potato?'+

to succesfully redirect to my community home page.

The documentation mentions the following:

redirect_uri—URI to redirect the user to after approval. This URI must match one of the values in the Callback URL field in the connected app definition; otherwise, the approval fails. This value must be URL encoded.

therefore, to avoid any issues with redirection, this variable MUST be URL Encoded.

| improve this answer | | | | |

I Just copied your code and tested; And it was working as expected.

But later I replicated issue and found that it's happening only if you pass your current community url as redirect_uri.

But it's weird, it's not expected behavior. I just read the doc for this component (https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_force_navigateToURL.htm) multiple times and got stuck here- "do the right thing".

mailto:, tel:, geo:, and other URL schemes are supported for launching external apps and attempt to “do the right thing.” However, support varies by mobile platform and device. mailto: and tel: are reliable, but we recommend that you test any other URLs on a range of expected devices.

So, my assumption is this component works with only well written URL. For example, redirect uri does not seem ok; there should not be & just after /; usually parameters starts with ?


So I just replaced this parameter as:


And it's working now as expected.

Lightning Component:

 <aura:component implements="forceCommunity:availableForAllPageTypes" access="global" >
    <lightning:button onclick="{!c.redirect}" label="redirect"> </lightning:button> 


    redirect : function(component, event, helper) {
        var urlEvent = $A.get("e.force:navigateToURL");
              "url": 'https://www.3rdPartyWebSite.ca/potatootherpotato=1&potatotwo=2&redirect_uri=https://MyCommunityURL.force.com/something/s?state=something'

And it's redirected to:

enter image description here

| improve this answer | | | | |
  • You are right ...I was able to replicate the issue...and found root cause as well....let me update my answer! – Ayub Mar 30 '18 at 19:08
  • I don't know about backend process of this component but tried lot to impress you! You guys are motivation and would not like to get downvote from you:) – Ayub Mar 30 '18 at 19:23
  • the thing is that changing the declarative simbol of the first parameter from ? to & is not accespted by the OAUTH2 provider, and returns a 404 =( . unfortunately, this does not fix the underlying issue. Additioanlly, redirect_uri is as valid of a parameter as any other. – glls Mar 30 '18 at 19:26
  • Sorry, but the '?' is a hierachical identifier that cannot be ranomly changed or removed as per RFC standards and serves a very specific purpose. If in your answer you propose to change this just for the sake of making the redirection work, it is not really an answer... – glls Mar 30 '18 at 20:26
  • And who deleted my last comment? – Ayub Apr 2 '18 at 14:12

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.