让堆栈导航器始终呈现initialRoute [英] Have a stack navigator always render initialRoute
问题描述
我正在构建一个React本机应用程序,并且正在使用react-navigation软件包.我为应用程序提供了一个标签导航器,每个标签中都有一个堆栈导航器.像这样:
I'm building a react native app and I'm using react-navigation package. I have a tab navigator for the app and each tab has a stack navigator in it. Something like this:
const HomeStack = StackNavigation({
Info: {screen: Info},
Main: {screen: Main}
})
const SearchStack = StackNavigation({
Search: {screen: Search},
SearchResult: {screen: SearchResult}
})
TabNavigation({
Home: {screen: HomeStack},
Search: {screen: SearchStack}
})
因此,假设我进行了搜索,现在进入SearchResult屏幕.然后,我通过按主页"选项卡返回主屏幕.现在,当我返回到搜索"选项卡时,它将显示搜索结果"屏幕.从选项卡转到搜索屏幕时,是否有办法强制其始终显示搜索屏幕?
So let's say I did a search and I'm now on SearchResult screen. I then go back to Home screen by pressing home tab. Now when I go back to search tab it shows me the SearchResult screen. Is there a way to force react-navigation to always render a Search screen when you go to it from the Tab?
我制作了一个零食项目来说明 https://snack.expo.io/rkMzWoh17
I made a project on snack to illustrate this https://snack.expo.io/rkMzWoh17
推荐答案
在这样的搜索堆栈导航中使用这样的初始路由名称
use initial route name like this in searchstack navigation like this
{
initialRouteName: 'Search',
}
这篇关于让堆栈导航器始终呈现initialRoute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!