+ Start a Discussion
Base Line 7Base Line 7 

Using pagereference to navigate to a webpage

I have added a custom button to a page that should navigate to a web page (https://www.google.com) when it is clicked. However, I get an error message stating, "Page doesn't exist. Enter a valid URL and try again." Here is the code I wrote for the navigation:
 
var navigService = cmp.find("navService");

var PageReference = {
            type: 'standard__webpage',
            attributes: {
                url: 'https://www.google.com'
            }
};

navigService.navigate(PageReference);
Looking at the documentation provided by Saleforce, this should work without any problem but that does not seem to be the case. Can someone please help me to figure out why it is not working? Thanks in advance.
 
Best Answer chosen by Base Line 7
Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

You need to use standard__webPage instead of standard__webpage as lightning is case sensitive, it is based on aura framework which is a type of JavaScript and JavaScript is case sensitive. 

Try below code:
var navigService = cmp.find("navService");
        var PageReference = {
            type: 'standard__webPage',
            attributes: {
                url: 'https://www.google.com'
            }
        };
        navigService.navigate(PageReference);

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas

All Answers

Khan AnasKhan Anas (Salesforce Developers) 
Hi,

Greetings to you!

You need to use standard__webPage instead of standard__webpage as lightning is case sensitive, it is based on aura framework which is a type of JavaScript and JavaScript is case sensitive. 

Try below code:
var navigService = cmp.find("navService");
        var PageReference = {
            type: 'standard__webPage',
            attributes: {
                url: 'https://www.google.com'
            }
        };
        navigService.navigate(PageReference);

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
This was selected as the best answer
Base Line 7Base Line 7
Many thanks to you Khan. You're the man!