Sam Rao
Sam Rao

Reputation: 4551

React Native: Getting a "there is no route key defined" error

My code is located here

i am getting an error that says: There is no route defined for key employeeList. Must be one of: 'auth','main'. I checked the router.js and the this component is nested in the main scene so i am not sure what the issue is. i am getting this when i wish to create an employee or delete an employee,. I believe it has to do with navigating back to the employeelist screen.

enter image description here

Upvotes: 3

Views: 1655

Answers (1)

Anamul Haque
Anamul Haque

Reputation: 7309

Change to and import stack from react-native-router-flux and do it for root, auth as well.

When you go to the first element of a stack, you call it with its key. That means if you want to go to employeeList you have to call Actions.main().

Thats why people usually name their parent stack with the name of the screen and first with "_" prefix. You could name your stack with employeeList and first scene with _employeeList. Try this and let me know the outcome please

<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>

Upvotes: 2

Related Questions