+ Start a Discussion
Koustubh MasurkarKoustubh Masurkar 

Navigation in lightning out for LWC

I have a LWC which navigates to records using NavigationMixin. When I use the same LWC in VisualForce page using lightning out, the navigation does not work. I there any way to make it work? I did research but didn't find any.
Best Answer chosen by Koustubh Masurkar
Koustubh MasurkarKoustubh Masurkar

Get the theme
public with sharing class ThemeTest {
    @auraEnabled(cacheable=true)
    public static String getUIThemeDescription() {
        String theme = UserInfo.getUiThemeDisplayed();
        return theme;
    }
}

Check the theme and navigate
    @track isLightning=false;
    @wire(getUITheme) theme({error,data}){
        if(data==='Theme4d'){             
            this.isLightning=true; 
        }  
        if(error){             
            this.error = error; 
        }                     
    }

    navigateToRecordViewPage(event) {
        this.record = event.detail.row;
        if(this.isLightning===true){
            this[NavigationMixin.GenerateUrl]({
                type: 'standard__recordPage',
                attributes: {
                    recordId: this.record.id,
                    actionName: 'view'
                }
            }).then(url => {
                window.open(url);
            });
        }
        else{
            window.location.assign(window.open('/'+this.record.id));
        }
    }

 

All Answers

Koustubh MasurkarKoustubh Masurkar

Get the theme
public with sharing class ThemeTest {
    @auraEnabled(cacheable=true)
    public static String getUIThemeDescription() {
        String theme = UserInfo.getUiThemeDisplayed();
        return theme;
    }
}

Check the theme and navigate
    @track isLightning=false;
    @wire(getUITheme) theme({error,data}){
        if(data==='Theme4d'){             
            this.isLightning=true; 
        }  
        if(error){             
            this.error = error; 
        }                     
    }

    navigateToRecordViewPage(event) {
        this.record = event.detail.row;
        if(this.isLightning===true){
            this[NavigationMixin.GenerateUrl]({
                type: 'standard__recordPage',
                attributes: {
                    recordId: this.record.id,
                    actionName: 'view'
                }
            }).then(url => {
                window.open(url);
            });
        }
        else{
            window.location.assign(window.open('/'+this.record.id));
        }
    }

 
This was selected as the best answer
Dinesh1617Dinesh1617
Hi. Does this solution work out for you?? When I implemented the same, receiving an error cross javascript error. Since LWC which is embedded in the VF page is trying to override the URL. let me know if we need to do any config changes to enable this to work.