You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 14:24:34