Share JavaScript Code in Lightning Web Component to Read URL Parameters

Building Reusable LWC Component to read query string from URL

Reusable Javascript Method

In this post, we would create a Lightning Web Component that can be shared across other LWC as a JavaScript library.

We are going to create LWC Component to acts as a utility method to read query parameter , as shown below

As you can see in above code, we just need to create a JavaScript file & meta file for LWC to act as Javascript library. Also, note how function is defined using keyword export. You can have multiple export methods in same LWC that would be used as library in your project.

To use above method in any LWC component, follow below syntax

Related posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.