DEV Community

bhanukarkra
bhanukarkra

Posted on

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

Top comments (0)