1

I am using a <lightning:verticalNavigation> which calls a method to redirect to a Lightning Community page.

Component

<lightning:navigation aura:id="navService" />

<lightning:verticalNavigation onselect="{! c.handleClick }">
    <lightning:verticalNavigationSection label="My Account">
        <lightning:verticalNavigationItem label="My Profile" name="my-profile" 
    </lightning:verticalNavigationSection>
</lightning:verticalNavigation>

Controller

handleClick: function (cmp, event, helper) {

    var selected = event.getParam('name');

    var navService = cmp.find("navService");

    var pageReference = {
        type: 'standard__navItemPage',
        attributes: {
            "apiName": "/my-profile"
        }
    };

    navService.navigate(pageReference)
},

Yet, the page does not redirect.

Questions

  1. What am I doing wrong?
  2. How can I fix it?
  • 2
    Last I had known this does not work in communities. – Jayant Das May 24 at 22:45
  • Using $A.get("e.force:navigateToURL"); opens the page in a new window... – Robs May 24 at 22:53
2

Looks like as a part of summer19 release (https://releasenotes.docs.salesforce.com/en-us/summer19/release-notes/rn_networks_navigationenhancements.htm), for communities the navigation can be achieved using below

handleClick: function (cmp, event, helper) {

var selected = event.getParam('name');

var navService = cmp.find("navService");

var pageReference = {
    type: 'comm__navItemPage',
    attributes: {
        "apiName": "/my-profile"
    }
};

   navService.navigate(pageReference)
},

Note that you can also use $A.get("e.force:navigateToURL")

For not opening in the new window use the relative url

  • Thanks. But I used the relative URL and it still opened in a new tab/window. – Robs May 25 at 8:52

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.