这是createStackNavigator({...})
的工作代码块,其中initialRouteName
的块已被注释掉。
const navigator = createStackNavigator(
{
Event: Event,
Signup: Signup,
Verif1: Verif1,
Chat: {
screen: ChatWithSocket,
}
}, /*{
initialRouteName: Signup,
} */
);
const AppContainer = createAppContainer(navigator);
export default AppContainer;
该应用正在运行React Native 0.59.5
和react navigation 3.9.1
。如果启用了initialRoutesName
的代码块(已删除注释)。然后弹出一个错误:
根据我的在线阅读情况,该问题似乎是React Navigation
模块的配置问题。
答案 0 :(得分:3)
我不得不将 {path: 'home', component: FrontHomeComponent},
{
path:'admin',
component: AdminComponent,
children:[
{path: '', redirectTo: 'login', pathMatch: 'full'},
{path: 'login', component: LoginComponent },
{path: 'register', component: RegisterComponent},
{path: 'header', component: HeaderComponent, canActivate: [AuthGuardService]},
{path: 'footer', component: FooterComponent, canActivate: [AuthGuardService]},
{path: 'manage-customer', component: ManageCustomerComponent, canActivate: [AuthGuardService]},
{path: 'view-customer', component: ViewCustomerComponent, canActivate: [AuthGuardService]},
]
},
切换为initalRouteName
initialRouteParams
答案 1 :(得分:0)
这是工作代码。初始路由的名称是一个字符串:
const navigator = createStackNavigator(
{
Event: Event,
Signup: Signup,
Verif1: Verif1,
Chat: {
screen: ChatWithSocket,
}
}, {
initialRouteName: 'Signup',
}
);
const AppContainer = createAppContainer(navigator);
export default AppContainer;
答案 2 :(得分:0)
initialRouteName必须是列表之一。 以您的示例为例:它必须是Event或Signup或Verfy1或Chat
答案 3 :(得分:0)
它发生在我身上,当我从“react-navigation-stack”而不是“@react-navigation/stack”导入时,如下所示:
import { createStackNavigator } from 'react-navigation-stack'
问题通过替换为:
import { createStackNavigator } from "@react-navigation/stack";