2

I create a force.com Site using visualforce page. Within the VF Page is a lwc that uses a to create new record and I want to navigate to a thank you page after record is created. I used extends NavigationMixin(LightningElement) to navigate to a webpage but when I run it the does not show. Is there a way to navigate to a webpage in LWC?

Here is my js controller

import { LightningElement, track, wire } from 'lwc'; 

import { NavigationMixin } from 'lightning/navigation';

export default class AccountViewLWC extends NavigationMixin(LightningElement) {
     
    handleSubmit(event) {
        console.log('onsubmit event recordEditForm'+ event.detail.fields);
        this.navigateToWebPage();
    }

    navigateToWebPage() {
        // Navigate to a URL
        this[NavigationMixin.Navigate]({
            type: 'standard__webPage',
            attributes: {
                url: 'http://google.com'
            }
        },
        true // Replaces the current page in your browser history with the URL
      );
    }
}
1
  • Please use the { } button or triple backticks for multiline syntax highlight. Single backtick is for inline comments. Oct 4 '20 at 13:18
1

Navigation mixin is not supported in lightning out for Visualforce or inside any other containers.

The lightning/navigation service is supported only in Lightning Experience, Lightning communities, and the Salesforce app. It isn’t supported in other containers, such as Lightning Components for Visualforce, or Lightning Out. This is true even if you access these containers inside Lightning Experience or the Salesforce app. The playground doesn’t support the lightning/navigation service.

Reference

You need to use the standard JS API,

window.open("http://google.com");

or

window.location.assign("http://google.com");
1
  • 2
    Or window.location, etc.
    – sfdcfox
    Oct 4 '20 at 13:25

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.