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: 299

10 Comments

  1. Thanks so much for this one! any pointers on what exactly the above javascript function does?

    • Thanks for your comment however this is working and the syntax is completely different. Why do not your post by your name instead of going anynomous.

    • 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.

  2. window.location.reload();

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

Comments are closed.

Discover more from Panther Schools

Subscribe now to keep reading and get access to the full archive.

Continue reading