How to Refresh Page using Lightning Web Component

Hi Trailblazer,

I came across a scenario where I need to refresh the whole page after we perform the logic from an inline LWC. After hitting hard I found below solutions.

  • Use Web Component inside Aura Component and then dispatch the event from the LWC which will be handled by parent AURA Component and then from Aura Component refresh the page.
  • Use eval JavaScript function to refresh the page from the LWC itself. Below is the code for the same, copy and paste the code after the line from where you wanted to refresh the page.
eval("$A.get('e.force:refreshView').fire();");
Amit Singh
Amit Singh

Amit Singh aka @sfdcpanther/pantherschools, a Salesforce Technical Architect, Consultant with over 8+ years of experience in Salesforce technology. 21x Certified. Blogger, Speaker, and Instructor. DevSecOps Champion

Articles: 292

Newsletter Updates

Enter your email address below and subscribe to our newsletter

10 Comments

    • I think you didnt understand what the author was saying. LWC doesnt have a force:refreshView event but aura does. We also know that we can host an LWC inside an aura. This point revolves around these 2 points. I think the author has read sufficient books and has significant experience to be able to present this ingenious idea. If you do not agree present your arguments rationally rather than posting unnecessarily rude comments.

      • The problem is that the first point mentions an Aura Component. The second point, by NOT mentioning an Aura Component, makes it sound like you don’t need one. If in fact it does, that should be clarified.

  1. window.location.reload();

    We can use above javascript code directly inside LWC to reload the page.

Leave a Reply

Your email address will not be published. Required fields are marked *