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);
}
}
Best Answer
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.