反应本机导航抽屉 - 打开页面不在抽屉中

时间:2018-06-17 19:02:22

标签: react-native navigation-drawer react-navigation

我是React Native开发的新手,很抱歉,如果这看起来很明显。

我有一个使用React Navigation Drawer作为其主要导航方法的新应用。如何在导航到导航抽屉中不存在的组件的页面中具有onPress功能?

this.props.navigation.navigate('示例')似乎只适用于抽屉中定义的页面。

我的抽屉配置:

<?php
header("Content-Type:application/json");
require 'checkSQLInsertion.php';

// read the incoming POST body (the JSON)
$input = file_get_contents('php://input');

if($input) 
{
$SQLInsertStatus=get_insertStatus($input);

if($SQLInsertStatus)
{
    response(200,1);//No SQL Insertion
}
else
{
    response(200,0); //Successful SQL Insetion
}

}
else
{
response(400,"If you can see this, then Web Service is Working, try 
again!! ");
}

function response($status,$ack)
{
header("HTTP/1.1 ".$status);

$response['status']=$status;
$response['status_message']=$ack;

$json_response = json_encode($response);
echo $json_response;
}

我正在按下按钮内的按钮&#34;应导航到上面配置中未包含的组件。

1 个答案:

答案 0 :(得分:3)

您可以在应用程序中使用多个导航器(通常情况就是如此),实际上每个要导航到的屏幕都应该在导航器中定义。导航器中的每个键可以是单个屏幕或其他导航器(Stack-,Drawer-,Tab-或SwitchNavigator)。

const DrawerRoutes = createDrawerNavigator({
  // your drawer navigator implementation ... 
});

const MyApp = createSwitchNavigator(
  {
    Drawer: DrawerRoutes,
    Example: YourScreen, // this would be the screen you want to navigator to
  },
  {
    initialRouteName: 'Drawer'
  }
);

现在,只需在抽屉内调用 this.props.navigation.navigate(&#39;示例&#39;),即可导航至YourScreen。

在反应导航应用程序中,拥有大量嵌套导航器并不罕见,但总有一个根导航器。