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.

  • Did you ever figure out how to do this in a console app? I am looking to detect when user activates different tabs within Service Console. I am happy to create an LWC for this but not sure how to detect the different tab clicks. Thanks!
    – DaloP
    Commented Jul 24, 2023 at 6:27

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? Commented 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. Commented 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! Commented Jan 23, 2021 at 23:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .