I am building a lightning community using LWC, where on successful login trying to navigate to standard home page of the community, but i see no URL redirection is happening.Below is the logic i have written.
import { LightningElement } from 'lwc';
import authenticateLogin from "@salesforce/apex/Login_Controller.authenticateLogin";
import { NavigationMixin } from 'lightning/navigation';
export default class LoginPage extends NavigationMixin(LightningElement){
handleLogin(event) {
var userName= this.template.querySelector(".userName");
var password = this.template.querySelector(".password");
authenticateLogin({ userName: userName.value , password : password.value})
.then(result => {
console.log("Auth success ! ");
this[NavigationMixin.Navigate]({
type: 'comm__namedPage',
attributes: {
pageName: 'home'
}
});
console.log("Navigation success ! ");
})
.catch(error => {
this.error = error;
console.log("error "+error);
})
.finally(() => {
console.log("finally ");
});
}
}
On console.log i see both "Auth success !" and "Navigation success !" are coming but the redirection is not happening, am i doing anything wrong in this.
This is the help doc i am following to achieve this – https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.reference_page_reference_type
Best Answer
I had the exact same issue and fixed it adding the navigation menu bar on my login page.
In my case, I had to make a custom theme Layout. For that I created an aura component in which I added a custom navigation bar (another aura component that I had to create because I needed to override the "Home" button functionality) adding the following div:
(Use this documentation as reference: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/components_config_for_builder_theme_layout.htm)
The result .cmp file of the custom layout component will be something like this:
I don't know if while using a standard theme you need to explicitly add to the page the navigation bar.