Suppose I have surfaced an LWC as a custom tab in a Lightning application by using the <target>lightning__Tab</target> in the metadata file. The LWC has some state. If I navigate away to another tab (for instance, a custom object tab) and return to the LWC tab, the state is still there. However, neither renderedCallback() nor connectedCallback() fires on the LWC when returning to the tab. Is there a good way to detect that the user came back?

One use case is wanting to reset some state.

1 Answer 1


Answering myself after some help from others!

Applying NavigationMixin, importing CurrentPageReference, and doing the following allows me to detect it.

setCurrentPageReference(currentPageReference) {
    console.log('Welcome to the tab ' + (new Date().getTime()) );
  • did you have to implement a LWC to navigate to your LWC tab to achieve this? Jan 23, 2021 at 3:26
  • @KrisGoncalves when I was testing this, I tested by 1. Click LWC tab. 2. Click custom object tab. 3. Click LWC tab again. Never did anything meaningful with this - it was simply for a proof of concept based on a student question. Jan 23, 2021 at 22:58
  • 1
    So I now see this does work in standard apps, but it doesn't seem to work in console apps (which is what I was using). Might create my own question. Thanks! Jan 23, 2021 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.