【发布时间】:2017-12-10 20:22:16
【问题描述】:
我的代码位于here
我收到一条错误消息:没有为关键的employeeList 定义路由。必须是以下之一:'auth'、'main'。我检查了 router.js 并且这个组件嵌套在主场景中,所以我不确定问题是什么。当我希望创建员工或删除员工时,我会得到这个。我认为这与导航回员工列表屏幕有关。
【问题讨论】:
标签: react-native react-redux react-native-router-flux
我的代码位于here
我收到一条错误消息:没有为关键的employeeList 定义路由。必须是以下之一:'auth'、'main'。我检查了 router.js 并且这个组件嵌套在主场景中,所以我不确定问题是什么。当我希望创建员工或删除员工时,我会得到这个。我认为这与导航回员工列表屏幕有关。
【问题讨论】:
标签: react-native react-redux react-native-router-flux
从 react-native-router-flux 更改并导入堆栈,并为 root、auth 执行此操作。
当您转到堆栈的第一个元素时,您使用它的键调用它。这意味着如果你想访问employeeList,你必须调用Actions.main()。
这就是为什么人们通常用屏幕名称来命名他们的父堆栈,并首先使用“_”前缀。你可以用employeeList 命名你的堆栈,用_employeeList 命名第一个场景。试试这个,请告诉我结果
<Router navigationBarStyle={{ backgroundColor: '#2980b9'}} titleStyle={{ color:'#fff', alignSelf:'center' }} >
<Stack key="root" hideNavBar={true}>
<Stack key='auth'>
<Scene key='login' component={LoginForm} title = 'Please login' />
</Stack>
<Stack key='employeeList'>
<Scene
key='_employeeList'
component={EmployeeList}
title ='Employee'
rightTitle="Add"
onRight={()=> Actions.createEmployee()}
initial
rightButtonTextStyle ={{ color:'white',alignSelf:'center',marginRight:5 }}
/>
<Scene
key='createEmployee'
component={EmployeeCreate}
title='Create Employee'
/>
</Stack>
</Stack>
</Router>
【讨论】: