NavController how to clear stack with Tabs

Hi everyone, my project is organized in this way:
Tab 1 -> Page1 -> Page2 -> Page3
Tab 2 -> Page1 -> Page2

I’m navigating through pages using NavController.navigateRoot() because I want that if the user clicks on the back-button it redirects to the root of the tab. This method works pretty well if I navigate through pages inside the same Tab but doesn’t work if from a Tab I redirect the user to another Tab. Here are two examples:

An example that works:
Tab1 -> Page1 -> Page2 -> back-button -> Root of Tab1

An example that not work:
Tab1 -> Page1 -> Page2 -> Tab2Page2 -> back-button -> Root of Tab2
But if I tap on Tab1 it’s still on its Page2 and not on its root (root of Tab1)

How can I achieve this?

I know that each tab has his own navigation history so I think that a solution could be clear tab navigation history when a tab is selected, but I want this only for Tab1 (if the user is on Tab2Page2 and taps on Tab1, I want Tab1 to be in the root but if he taps again on Tab2 it has to be on Tab2Page2).

Should I clear history only for Tab1, or there is a more elegant method to achieve this using navController.navigateRoot?

Thank you all!