title: Jetpack Compose Navigation: PopUpTo Screen from Screens that have same route except argument
body: <p>navigation compose version <code>2.4.0-alpha06</code></p>
  <p>I have a Navigation Drawer using <code>Scaffold</code> and part of the items are dynamically generated by ViewModel.</p>
  <p>Example items are</p>
  <ul>
  <li>Home</li>
  <li>A</li>
  <li>B</li>
  <li>C
  ...</li>
  <li>Settings</li>
  </ul>
  <p>where A, B, C, ... all share same <code>Screen</code> called <code>Category</code>, with just different arguments passed (e.g. Category/A, Category/B).</p>
  <p>Inside my <code>Scaffold</code></p>
  <pre class="lang-kotlin prettyprint-override"><code>...
  
  val items = viewModel.getDrawerItems()
  // This gives something like 
  // [&quot;Home&quot;, &quot;Category/A&quot;, &quot;Category/B&quot;, &quot;Category/C&quot;, ..., &quot;Settings&quot;] 
  // where each String represents &quot;route&quot;
  
  ...
  
  val backstackEntry = navController.currentBackStackEntryAsState()
  val currentScreen = Screen.fromRoute(
      backstackEntry.value?.destination?.route
  )
  Log.d(&quot;Drawer&quot;, &quot;currentScreen: $currentScreen&quot;)
  
  items.forEach { item -&gt;
      DrawerItem(
          item = item, 
          isSelected = currentScreen.name == item.route, 
          onItemClick = {
              Log.d(&quot;Drawer&quot;, &quot;destinationRoute: ${item.route}&quot;)
              navController.navigate(item.route)
              scope.launch {
                  scaffoldState.drawerState.close()
              }
          }
      )
  }
  </code></pre>
  <p>This code works pretty well, except when I visit Home screen, I want to clear all backstack upto Home not inclusive.</p>
  <p>I've tried adding <code>NavOptionsBuilder</code></p>
  <pre class="lang-kotlin prettyprint-override"><code>...
  
  navController.navigate(item.route) {
      popUpTo(currentScreen.name) {
          inclusive = true
          saveState = true
      }
  }
  ...
  </code></pre>
  <p>However, this doesn't work because <code>currentScreen.name</code> will give something like <code>Category/{title}</code> and popUpTo only tries to look up exact match from the backstack, so it doesn't pop anything.</p>
  <p><strong>Is there real compose-navigation way to solve this? or should I save the last &quot;title&quot; somewhere in ViewModel and use it?</strong></p>
  <p><a href="https://developer.android.com/codelabs/jetpack-compose-navigation#0" rel="nofollow noreferrer">This tutorial from Google</a> has similar structure, but it just stacks screens so going back from screen A -&gt; B -&gt; A and clicking back will just go back to B -&gt; A, which is not ideal behavior for me.</p>
  <p>Thank you in advance.</p>