0

I am trying to navigate to a record page in a new tab using the NavigationMixin service. Below code. Even though the record opens in a new tab, the current tab also navigates to the new record (The current tab and the new tab both navigates to the record page.) How can I stop navigating the current tab?

sample.html

  <template>
         <a href="javascript:void(0)" onclick={openRecord} data-recid={user.Id}>
            {user.Name}
         </a>
  </template> 

sample.js

  import {LightningElement, wire} from 'lwc';
  import { NavigationMixin } from 'lightning/navigation';

  export default class UsermanageLoginHistory extends NavigationMixin(LightningElement) {

    @wire(getUserInfo, {
            usrId: '005xxxxxxxxxxxx',
          })
     applications({ data}) {
        if (data) {
             this.user = data;
        }



   openRecord(event) {

     event.stopPropagation();
     event.preventDefault();

     let recId = event.target.dataset.recid;

     this.userDetailNavigateRef = {
        type: 'standard__recordPage',
        attributes: {
            recordId: recId,
            actionName: 'view'
        }
     };
     this[NavigationMixin.GenerateUrl](this.userDetailNavigateRef)
         .then(url => { window.open(url, "_blank") });

     this[NavigationMixin.Navigate](this.userDetailNavigateRef);

    }

  }
0
4

It is likely the last line in the code.

You should remove the last line this[NavigationMixin.Navigate](this.userDetailNavigateRef); It is causing the navigation of the same tab.

1
  • yup. that did the trick. Thanks.. – Brav May 9 '20 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.