How to navigate to a page in LWC after button click/record creation

bhanukarkra

bhanukarkra

Posted on June 28, 2022

How to navigate to a page in LWC after button click/record creation

use navigation mixing

1)Add library

import { NavigationMixin } from 'lightning/navigation';
Enter fullscreen mode Exit fullscreen mode

2)add navigation mixing in default class

export default class ObservationCreationPage extends NavigationMixin(LightningElement) {
Enter fullscreen mode Exit fullscreen mode

3)add navigation mixing in function


handleSuccess(event) {
        this.loaded = true;
        this.closeQuickAction()
Successfully!! ${event.detail.id}`, "success")
        console.log("handle Success",JSON.stringify(event.detail))
        this.showToast("Success!!", `Observation Created Successfully!!   Obs No.: ${event.detail.fields.Name.value}`, "success")
        this[NavigationMixin.Navigate]({
            type: 'standard__recordPage',
            attributes: {
                recordId: event.detail.id,
                actionName: 'view'
            }
        });
    }

Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
bhanukarkra
bhanukarkra

Posted on June 28, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related