NavigationMixin Not Working on Community – How to Fix Navigation Issues in Salesforce Experience Cloud

customer-communityexperience-cloudjavascriptlightning-web-componentsnavigationmixin.navigate

I want to navigate from lwc component firstComponent to a community page enerie test.

FirstComponent

import { NavigationMixin } from 'lightning/navigation';

export default class FicheNutrition1 extends NavigationMixin(LightningElement) {
...
handleLevier1Click() {
        console.log('this is levier 1');
        this[NavigationMixin.Navigate]({
            type: 'comm__namedPage',
            attributes: {
                pageName: 'energie_test__c'
            },
        });
        console.log("##############");
    }
...
}

API name of the page: energie_test__c . it contains a custom lightning component. I tried navigating to the component first but it didn't work either.

Best Answer

For comm__namedPage use the name attribute

this[NavigationMixin.Navigate]({
    type: 'comm__namedPage',
    attributes: {
        name: 'energie_test__c'
    },
});