I'm working on a Lightning component that includes a button, whose purpose is to load a Visualforce page rendering a PDF cover sheet. I'd like to use the most current supported functionality, so I'm using <lightning:navigation>
to manage URL generation.
<lightning:navigation>
is documented to support seven pageReference
types, one of which is "Navigation Item Page".
This includes Visualforce pages which have custom tabs assigned to them - the tab's API name can be used as the target API name of the page reference. Using the Visualforce page's own API name does not work.
My controller does this:
let pageReference = {
type: 'standard__navItemPage',
attributes: {
apiName: 'Cover_Sheet'
},
state: {
caseNumber: component.get('v.caseRecord.CaseNumber'),
// ... other parameters ...
}
};
component.find('navService').generateUrl(pageReference)
.then($A.getCallback(function(url) {
window.open(url);
}), $A.getCallback(function(error) {
helper.showToast('Unable to open cover sheet.', error);
}));
},
The URL that's generated looks reasonable:
https://mysandbox.lightning.force.com/lightning/n/Cover_Sheet?caseNumber=03107407...
although the /n/
format appears to be the new standard for targeting a named tab.
When I get into Visualforce, I do
System.debug(ApexPages.currentPage().getParameters());
and I don't find any of the parameters I wanted to set represented there:
11:36:56:051 USER_DEBUG [8]|DEBUG|{clc=1, isdtp=p1, ltn_app_id=06mC00000018GYXIA2, nonce=XXXXXXX, sfdc.tabName=01rW000000016SV, sfdcIFrameHost=web, sfdcIFrameOrigin=XXXXXX, tour=, vfRetURLInSFX=/home/home.jsp}
Being in a console or standard app doesn't make a difference.
Edit: Additionally, I tried prefixing the entries within the state
key with c__
, as with Lightning component attributes; this had no effect.
Is it possible to use <lightning:navigation>
to target a Visualforce page while providing parameters in the URL, or are we stuck using other techniques to load the page?
pageReference
types, it is not clear ifstate
can be actually used with all the different types as it only finds its references in some of those. That possibly could be a pointerstate
does not have any impact on other types. That's just a guess.