[SalesForce] Avoid navigation to newly created record using NavigationMix

I'm working on a requirement where I want a button which will open a modal to create a new Task record in LWC. For this, I tried using NavigationMixin. But onclick of Save in the modal, it redirects to the newly created record page instead of closing the modal. Is there any way to skip the navigation to the newly created record and close the modal only.

Below is the code of NavigationMixin that I'm using:

this[NavigationMixin.Navigate]({
    type: 'standard__objectPage',
    attributes: {
        objectApiName: 'Task',
        actionName: 'new'
    }
});

Thanks in advance.

Best Answer

this[NavigationMixin.Navigate]({
  type: 'standard__objectPage',
  attributes: {
      objectApiName: this.childObjectApiName,
      actionName: 'new'                
  },
  state : {
      count: '1',
      nooverride: '1',
      useRecordTypeCheck : '1',
      defaultFieldValues: inheritParentString,
      navigationLocation: 'RELATED_LIST'
  }
});

You can append navigationLocation: 'RELATED_LIST' to state, and it will prevent navigation away from the current page. For some reason, this is not in the documentation and took me hours of crying into my palms before I found it in the url when using the action from a standard related list.