0

On my community page(A) I have a LWC component with a button which onclick will call an apex method to create a record. If the create is successfull it needs to redirect to another community page(B). Onclick calls the method handleConfirm. The issue I am facing is though the record is created/saved succesffully in the backend, the system doesn't redirect to the community page B. It remains on community page A. Through debug, I confirmed the code under the handleConfrim .then does get executed but nothing happens.
Below is the code snippet.

connectedCallback() {
    this.prod = something;
    getAsstPrgmLst({aId:this.prod})
    .then(result => {
        // does something in a for loop to populate some options.
    })
    .catch( 
        error => {
            this.error = error;
        })
    .finally(() => this.showflag = true );
}

handleConfirm(){
    createSubscription({aId: this.asstPgm.Id,
    ep:this.prgm, uId: this.userId})
    .then(result=>{
        this.isSuccess = true;
        this[NavigationMixin.Navigate]({
            type: 'comm__namedPage',
            attributes:{
                pageName:'connectpageB'
            }
        });
    })
    .catch(error =>{
        this.error = error;
    });
    
}

What I am doing wrong here? Any suggestions on how I could fix this issue.

3
  • LWC Developer guide states that the attribute property for name community pages is name and not pageName (Although, I've not tested it, I've seen some blogs stating that the usage of pageName works). Can you try with name attribute property?
    – arut
    Commented Nov 19, 2020 at 18:14
  • The navigation attributes are correct as it works fine in other functions without the imperative call. I have a doubt, the imperative call and the connectedCallback is messing with the flow, but can not figure issue out.
    – SFDCresh
    Commented Nov 19, 2020 at 20:08
  • Can you place some console.log statements insider the then & catch blocks to trace the execution flow? Also, why do you think connectedCallback would interfere here? It executes during the component rendering lifecycle (not necessarily during every event handling in the component).
    – arut
    Commented Nov 20, 2020 at 3:40

1 Answer 1

0

enter image description here

Import NavigationMixin and Apply the NavigationMixin to the component's base class.

2
  • Thanks, that's already been done and is part of the code.
    – SFDCresh
    Commented Nov 19, 2020 at 17:57
  • is the community page name is correct please check once? Commented Nov 19, 2020 at 18:18

You must log in to answer this question.

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