2

I'm using lightning navigation to redirect to a standard record page. However, the redirection takes place in the same tab. Is there a way to open a new tab?

navigateToRecord(event){
        var sRecordId = event.target.dataset.id;
        if(sRecordId!=='' && sRecordId!==undefined ){
            this[NavigationMixin.Navigate]({
                type: 'standard__recordPage',
                attributes: {
                    recordId: sRecordId,
                    objectApiName: 'My_Object__c',
                    actionName: 'view'
                },
            });
        }
        
    }
1
  • do you mean new tab on browser or new tab on console app?
    – User6670
    Jul 22 '20 at 11:15
3

Use NavigationMixin.GenerateUrl. Then use window.open to open in a new window.

this[NavigationMixin.GenerateUrl]({
    type: "standard__recordPage",
    attributes: {
        recordId: sRecordId,
        objectApiName: 'My_Object__c',
        actionName: 'view'
    }
}).then(url => {
    window.open(url, "_blank");
});
3
  • I actually tried this already. Seems, the redirection takes places before .then() gets called. So it doesn't even enter the .then() context.
    – sfdcnoob
    Jul 22 '20 at 11:55
  • Did you try this code? @sfdcnoob Jul 22 '20 at 12:00
  • 3
    @sfdcnoob its this[NavigationMixin.GenerateUrl] not this[NavigationMixin.Navigate]
    – User6670
    Jul 22 '20 at 12:00

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.