我'm new to React Native and I'目前正在研究React Native Navigation Docs . 我想知道: navigation.push()
和 navigation.navigate()
有什么区别?
我试着自己找出来,但他们似乎完成了同样的事情......
我'm new to React Native and I'目前正在研究React Native Navigation Docs . 我想知道: navigation.push()
和 navigation.navigate()
有什么区别?
我试着自己找出来,但他们似乎完成了同样的事情......
2 回答
如果您查看push的文档,可以解释它们的不同之处 .
我们可以以Instagram为例;
考虑导航到用户's profile. Then you can check user'的粉丝,然后您也可以导航到他们的 Profiles . 如果仅使用
navigate
操作执行相同的操作,当您从关注者列表屏幕单击用户的配置文件时,将导航到上一个配置文件,但如果您使用push
,则会将新屏幕推送到堆栈并显示正确的配置文件 . 这样你就可以goBack
到第一个屏幕 .根据上一篇博客文章here:for v1:
navigate(routeName) and push(routeName) were very similar: every time you called navigate(routeName) it would push a new route to the stack.
对于v2:
Now navigate(routeName) will first try to find an existing instance of the route and jump to that if it exists, otherwise it will push the route to the stack.
导航>如果存在则转到页面实例或推送新实例
push>推送一个新实例,即使已存在一个实例