1

UPDATE: I just verified it works when I navigate to my Lightning Component as part of a Lightning Page.

My company is still in classic, so we're wrapping our components in Visualforce. https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_visualforce.htm

Now, the question is how do I make PageReference/Navigation Link work in a Component, within a Visualforce page?

I've also now tried force:navigateToURL. Works fine when the component is in a Lightning Page, errors in a VF page. https://developer.salesforce.com/docs/component-library/bundle/force:navigateToURL/documentation

PRIOR: DefaultUrl seems to work as expected, but url is returning void. Why is that? I've tried other PageReference types, and url is always void.

enter image description here

<aura:component access="public" implements="force:appHostable,lightning:isUrlAddressable">
<aura:attribute name="url" type="String" />
<aura:attribute name="pageReference" type="Object"/>

<aura:handler name="init" value="{! this }" action="{! c.init }"/>


<lightning:navigation aura:id="navService"/>
<a href="{!v.url}">Link</a>

({
init : function(component, event, helper) {
    var navService = component.find("navService");
    var pageReference = {
        type: 'standard__navItemPage',
        attributes: {
            apiName: "MyVisualForcePage"   
        }
    };
    component.set("v.pageReference", pageReference);
    // Set the URL on the link or use the default if there's an error
    var defaultUrl = "apex/MyVisualForcePage";
    navService.generateUrl(pageReference)
        .then($A.getCallback(function(url) {

            console.log('### url' + url);
            console.log('### defaultUrl' + defaultUrl);

            component.set("v.url", url ? url : defaultUrl);
        }), $A.getCallback(function(error) {
            component.set("v.url", defaultUrl);
        }));
}

})

1
  • My suspicions are in the var pageReference parameters. Those need to be filled in properly to get the desired results Feb 24, 2020 at 21:44

1 Answer 1

1

Here what I see in the documentation To enable direct navigation to a Lightning component via URL, add the lightning:isUrlAddressable interface to the component. This interface is used with the lightning:navigation component to navigate from one component to the URL-addressable component. This navigation feature is supported only in Lightning Experience and the Salesforce App.

For force:navigateToURL I see below.

This event is handled by the one.app container. It’s supported in Lightning Experience, Salesforce app, and Lightning communities.

You need to check if user is in classic or lightning and then fire different mehod of navigation.

For classic you can use window.open it also works in lightning.

In short, you can not access those in classic.

1
  • Thanks Avijit. In the end, I found the same and ended up using window.open for classic. When we implement Lightning, we'll add the check for Lightning or Classic. Based on that, either use window.open or Navigation/PageReference as I was trying here. Feb 25, 2020 at 19:55

You must log in to answer this question.

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