Expo Router中(location)目录下index.tsx无法渲染的问题求助
Expo Router中(location)目录下index.tsx无法渲染的问题求助
我现在碰到个棘手的问题:(location)目录下的index.tsx文件怎么都渲染不出来。虽然该目录下的**_layout.tsx**组件能正常显示头部,但页面其他区域完全是空的。
我已经检查过站点地图了,系统是能识别到index.tsx文件的,实在搞不懂为啥它就是不渲染?
先给大家看看我的应用结构:
app/ ├── (location)/ | ├── _layout.tsx | ├── index.tsx ├── (stores)/ | ├── _layout.tsx | ├── index.tsx ├── _layout.tsx ├── index.tsx ├── searchStores.tsx
我是通过searchStores.tsx里这段代码跳转到(location)页面的:
router.push(`/(location)`);
这是(location)目录下的_layout.tsx组件代码:
import { View, Text, TouchableOpacity, StyleSheet } from "react-native"; import { useRouter } from "expo-router"; import { Ionicons } from "@expo/vector-icons"; const Header = ({ title, onBackPress, }: { title: string, onBackPress: () => void, }) => { return ( <View style={styles.header}> <TouchableOpacity onPress={onBackPress} style={styles.backButton}> <Ionicons name="arrow-back" size={30} color="black" /> </TouchableOpacity> <Text style={styles.title}>{title}</Text> </View> ); }; export default function Layout() { const router = useRouter(); const handleBackPress = () => { router.navigate("/searchStores"); }; return <Header title="Location" onBackPress={handleBackPress} />; } const styles = StyleSheet.create({ header: { flexDirection: "row", alignItems: "center", padding: 10, backgroundColor: "#f8f8f8", }, backButton: { marginRight: 50, marginLeft: 10, }, title: { fontSize: 20, fontWeight: "bold", }, });
这是我想要渲染的index.tsx文件代码:
import { View, Text } from "react-native"; const Index = () => { return ( <View> <Text>test screen</Text> </View> ); }; export default Index;
备注:内容来源于stack exchange,提问作者Hamza Malik
相关产品推荐
相关产品推荐

