[英]How can i make breadcrumbs/show screens path in react native (I am using react navigation v5)
[英]How can I set the initial state using react-navigation v5 to include screens as history?
假设我有以下路线结构:
Authenticated
- Main
- StackA
-ViewA
- StackB
-ViewB
- StackC
- ViewC
- ViewD
我想设置我的初始状态,以便我查看 ViewD,但我可以从左侧滑动以返回 ViewC。
此处的文档https://reactnavigation.org/docs/navigation-state/#partial-state-objects说我应该能够提供一组对象,每个对象都有一个映射到路由名称的name
属性,以初始状态的routes
属性,它将为我整理其余部分。 但是,当我这样做时,没有任何变化,并且呈现通常的初始状态。
根据上面链接的文档,这是我希望工作的初始状态:
{
routes: [
{ name: "Authenticated" },
{ name: "Main" },
{ name: "StackC" },
{ name: "ViewC" },
{ name: "ViewD" }
]
}
编辑
我通过使用以下初始状态设法解决了这个问题:
{
routes: [
{
name: "Authenticated",
params: {
screen: "StackC",
params: {
screen: "ViewD",
initial: false,
}
}
}
]
}
其中的关键部分是initial
属性。 这导致StackC
的初始路由在StackC
下ViewD
,这正是我想要的。
这是我在零食上创建的一个快速示例。 基本上,您需要创建一个屏幕数组,并使用重置功能。
const initialState = {
index: 4,
routes: [
{
name: 'Stack',
params: { screen: 'StackView1' },
},
{
name: 'Stack',
params: { screen: 'StackView2' },
},
{
name: 'Stack1',
params: { screen: 'Stack1View1' },
},
{
name: 'Stack1',
params: { screen: 'Stack1View2' },
},
{
name: 'Stack1',
params: { screen: 'Stack1View3' },
},
],
};
return (
<NavigationContainer initialState={initialState}>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.