2

I am trying to redirect on the a href click to a custom visualforce page in lightning.

<a href=# onclick={navigateto###} target="_blank"></a>


 navigateto###() {
        console.log('Inside navigate to home Tab');
        // Navigate to the Account home page
        this[NavigationMixin.Navigate]({
          type: 'comm__namedPage',
          attributes: {
           pageName: 'FileVie###',
          },
          state: {
           'fileId': '0685D00#####'
          }
         });
    }

But as standard way its apeending s to it. https://abc.force.com/s/FileVie###?fileId=0685D00#####

Is there any chances to remove s or any other way to redirect to a custom visualforce page with redirect. I have also used , custom URL however it is appending the url on the same community page not in a separate tab:

this[NavigationMixin.Navigate]({
        type: 'comm__namedPage',
        attributes: {
            pageName: 'https://wwww.salesforce.com'
        }

4 Answers 4

6
  1. In communities, only comm__namedPage page-reference will work.

  2. It will navigate to specified community page within community.

  3. You have to use component/page inside community page.

  4. Although you can pass the parameters through state, you cannot get the state from component as it is inside community page.

  5. If you want to get the data exchange, you can use browser storage like localStorage or sessionStorage.

Finally, what you are trying to do is not possible as of now. Instead, try implementing with work-around like above.

2
  • For #3 you say "you can pass the parameters through state" but the documentation says "Lightning communities don't support the state property" for PageReference. Do you have state working in a NavigationMixIn for comm__NamedPage? Mar 20, 2020 at 16:39
  • 1
    @DavidCheng, If you read it fully, I was saying you can pass the parameters BUT you can never read them Mar 30, 2020 at 2:20
8

I came in this answer I think we have one more way to do it.

You can pass parameters to the community with the following

Page to pass the parameters

this[NavigationMixin.Navigate]({
    type: 'comm__namedPage',
    attributes: {
        name: 'Register'
    },
    state: {
        emailParameter: '[email protected]'
    }
});

Page to Receive the parameter In the connectedCallback you can capture by

console.log('this.current', this.currentPageReference);
1
  • 2
    Actually, this neglected answer at the bottom of the page is correct. Even though the documentation specifies that only the name attribute can be passed in a Community / Experience page, it turns out that I could add the state, and it was read correctly. I was positively surprised, because I was resigned to complicated workarounds with LMS or the solution posted by @salesforce-sas. The only mistake Henrique made was to use name instead of "pageName" for the attribute. Once I fixed that, I was able to navigate passing params in Communities in a simple way. Thanks Henrique ! Mar 24, 2021 at 12:38
0

I know this is an old question but still want to share a nice hack for navigating to different pages in community (from LWC) without using navigation mixin. You can simply add the below function onto an event handler (e.g. onclick,onload, etc.) in order to navigate.

someFunction(){
    let urlString = '/your-page-name'; 
    eval("var urlEvent = $A.get('e.force:navigateToURL'); 
    urlEvent.setParams({'url': '" + urlString + "'});urlEvent.fire();");

}

-- Parikshit

1
  • This requires "your page name" to include any path defined for the specific digital experience site which is not a good idea. Better to use the mixin which should do that all for you.
    – Phil W
    May 11, 2022 at 20:27
0

Parikhit's code has a lot of syntax errors (won't run at all) and will not handle the 's' in the url. This is some code that will handle the s by getting the origin url and then tracking on visualforce page and parameters

        let urlString = window.location.origin+ 'apex/my_Page?param1=';
        let urlEvent = eval("$A.get('e.force:navigateToURL')"); 
        urlEvent.setParams({
            "url": urlString
        });
        urlEvent.fire();

You must log in to answer this question.

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