9

I'm trying the new jetpack library "compose-navigation".

According to the docs, to navigate to a route, I should use navigate() method which takes a String.

navController = rememberNavController()

// navigate
navController.navigate("/another_route")

However, no such method exists navigate(String) and I get compile error.

What am I missing?

Mahdi-Malv
  • 16,677
  • 10
  • 70
  • 117

1 Answers1

28

navigate(String) is not part of NavController class, but an extension function

To solve the error, "import the function route in the file":

import androidx.navigation.compose.navigate

// and then navigate
navController.navigate("/another_route")

And it'll work fine.

Unfortunately, you don't get the completion that you expect.

Mahdi-Malv
  • 16,677
  • 10
  • 70
  • 117