2

I have configured a Custom Menu on the header component on my Community(Napili template) using lightning:buttonMenu and had Logout as one of the menu items. Clicking on it, it would then redirect to a page(I call it as Logout screen).

if(selectedMenuItemValue == 'Logout'){
       var urlEvent = $A.get("e.force:navigateToURL");
         urlEvent.setParams({
             "url": '/logout' 
         });
         urlEvent.fire(); 

But how can I actually implement a Logout that happens from Standard Logout item from Community's default Profile Header?

9
  • 2
    Use "/secur/logout.jsp" Also if navigateToURL is not working then have a simple <a href> link and construct the ULR like this: SalesforceOrgURL+CommunityPrefix+'/secur/logout.jsp' Good idea is to keep the Org and Community in the custom label and construct them in the component as: <a href="{!$Label.c.OrgURL+'/'+$Label.c.Community_Prefix+'/'+'secur/logout.jsp'}" Logout </a> Commented May 15, 2017 at 4:14
  • I am afraid it didn't worked. It said: Invalid Page. What I did was, changed the url in my code to yours. (< _ >)
    – SatyaV
    Commented May 15, 2017 at 4:23
  • Can you please provide the code snippet? I am doing exactly the same and its working Commented May 15, 2017 at 4:26
  • Oh I missed your new edit. Let me try that and get back to you soon.
    – SatyaV
    Commented May 15, 2017 at 4:28
  • @JaiChaturvedi As I mentioned, Logout is one of the menu items <lightning:menuItem> under <lightning:buttonMenu>. I couldn't use a <a href> tag as its not working with buttonMenu tag. Is there any other work around? Thanks
    – SatyaV
    Commented May 15, 2017 at 4:40

2 Answers 2

3

I would use window.location.href=salesforceurl/secure/logout.jsp

This will use the current window to navigate to logout url

1
  • 2
    Cool. Working as I desired. Thank you for that. I would also appreciate @JaiChaturvedi for providing me insight on the possible solution.
    – SatyaV
    Commented May 15, 2017 at 5:49
1

you can also add additional parameter like:

window.location.href=<salesforce-url>/secure/logout.jsp?retUrl=http://google.com'

to redirect the user to home page of your application after successful logout.

1
  • 1
    I used this approach in my lightning component's controller. It logged out, but it didn't redirect to google. Is there any other approach to do the redirection?
    – SamuelDev
    Commented Mar 24, 2018 at 4:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .