【发布时间】:2020-07-23 12:38:45
【问题描述】:
我想将 React Navigation v5(抽屉导航)与 Next.js 一起使用,但我对它们的集成有疑问。
简而言之:基于 React Navigation Screens 组件的 React Navigation(抽屉式导航)。
它有条件地呈现正确的屏幕。
问题是: Next.js 有自己的基于文件夹结构的路由系统。例如。 /pages 文件夹中的每个文件都会自动生成一个适当的路径,因此我无法将这些文件添加为 React 导航屏幕(至少我不确定它是否可能)
如何让这些工具协同工作并保存 Next.js SSR 功能?
React 导航抽屉示例:
import * as React from 'react';
import { Button, View } from 'react-native';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';
function HomeScreen({ navigation }) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button
onPress={() => navigation.navigate('Notifications')}
title="Go to notifications"
/>
</View>
);
}
function NotificationsScreen({ navigation }) {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button onPress={() => navigation.goBack()} title="Go back home" />
</View>
);
}
const Drawer = createDrawerNavigator();
export default function App() {
return (
<NavigationContainer>
<Drawer.Navigator initialRouteName="Home">
<Drawer.Screen name="Home" component={HomeScreen} />
<Drawer.Screen name="Notifications" component={NotificationsScreen} />
</Drawer.Navigator>
</NavigationContainer>
);
}
感谢您的帮助!
【问题讨论】:
标签: reactjs react-native react-navigation next.js react-navigation-drawer