我正在尝试新的喷气背包库“ compose-navigation ”。
根据docs , 要导航到一条路线,我应该使用 navigate()
采用 的方法字符串 .
navController = rememberNavController()
// navigate
navController.navigate("/another_route")
但是,不存在这种方法 navigate(String)
我得到编译错误。我错过了什么?
最佳答案
navigate(String)
不属于 NavController
类,但是一个 扩展功能
要解决错误,“在文件中导入函数路由”:
import androidx.navigation.compose.navigate
// and then navigate
navController.navigate("/another_route")
它会正常工作。不幸的是,你没有得到你期望的完成。
关于android - 撰写导航中没有方法导航(字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64614983/