how to perform an action instead of moving to another destination if I click a menu in Navigation Drawer using Navigation Component?

I am trying to use Jetpack Navigation component. so navigation component will automatically handle if I want to segue from a destination to another destination when I click a menu in the navigation drawer

but I want to perform an action if a menu is clicked, say for example if a menu in drawer is clicked then I want to show a toast message.

in old way, ie using fragment transaction, I can easily check from onNavigationItemSelected, but I am no longer find that method

enter image description here

so how to do that in navigation component ?

I have tried to check onDestinationChanged , but it doesn’t work

override fun onDestinationChanged(controller: NavController, destination: NavDestination, arguments: Bundle?) {

        if ( == {

           // show toast in here
           // but it doesn't work


here is my MainActivity

class MainActivity : AppCompatActivity() {

    private lateinit var navController : NavController
    private lateinit var appBarConfiguration: AppBarConfiguration

    override fun onCreate(savedInstanceState: Bundle?) {

        appBarConfiguration = AppBarConfiguration(setOf(

        // init nav controller
        navController = Navigation.findNavController(this,

        // set toolbar

        // set up navigation drawer
        NavigationUI.setupActionBarWithNavController(this,navController, appBarConfiguration)



    override fun onSupportNavigateUp(): Boolean {
        return NavigationUI.navigateUp(navController,appBarConfiguration)



You can handle Menu clicks as following
                .setOnMenuItemClickListener { menuItem: MenuItem? ->
                 // write your code here