function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Afzaal HassanAfzaal Hassan 

How to convert Aura into a LWC JS code

I have a LWC code where if you click the button it generates a URL and then opens it. I have another aura component that is launched from a flow and it does the exact same thing as the LWC but this actually works and the LWC is not working. I was wondering if anyone could help me on how to rewrite the aura controller code as a LWC JS code? Here is the working aura code:
Component:
<aura:component implements="force:lightningQuickAction,lightning:availableForFlowActions">
<aura:attribute name="URLpassing" type="String"/> </aura:component>
JS cONTROLLER:
({
invoke : function(component, event, helper)
var URL = component.get("v.URLpassing");
var redirect = $A.get("e.force:navigateToURL");
// Pass the record ID to the event
redirect.setParams({ "url": URL, });
// Open the record
redirect.fire(); } })
The url is passed from a flow to this aura component
I want to replicate the controller code into my LWC JS so it behaves the same way. This is what my Lwc is doing:
HTML:
<template>
<div>
<lightning-button class="aButton" label="URLCreator" onclick={UrlCreator}>
</lightning-button>
</div> </template>
JS:
export default class URLCreate extends NavigationMixin(LightningElement) {
@api recordId;
@api accId;
@track PageUrl;
URLCreator(event) {
this.PageUrl = '/apex/AVFpage_HTML';
this.PageUrl += "&accountId="+ this.accId; this[NavigationMixin.GenerateUrl]
({ type: 'standard__webPage',
attributes: { url: this.PageUrl } }).then(generatedUrl => {
//this set of code I dont think is working. I need to replicate this like my aura controller code
sforce.one.navigateToUrl(generatedUrl); });
}
If anymore can help, that would create. Again, since my aura is working, I would like to mimic the functionality/code into my LWC but I dont know how to write that aura functionality as LWC Thank you
AbhishekAbhishek (Salesforce Developers) 
https://terencechiu.com/2019/05/21/migrating-aura-component-to-lightning-web-component/

The above blog has some examples which might help you.

For reference check this too (https://developer.salesforce.com/docs/component-library/documentation/en/lwc/migrate_introduction).


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.

Thanks.