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.
<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);
}));
}
})
var pageReference
parameters. Those need to be filled in properly to get the desired results