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

React Native Expo项目布局不显示问题及解决方法咨询

解决Expo + Expo Router布局不显示的问题

核心问题分析

  • app目录下的index.js中定义的Home组件未返回JSX内容,组件无法渲染任何布局
  • 根目录index.js的配置不符合expo-router的要求,错误导出了Home组件

具体修复步骤

1. 修正根目录index.js

根目录的index.js只需要负责引入expo-router的入口,不需要导出Home组件,修改为:

import 'expo-router/entry';

2. 修复app目录index.js的Home组件

确保Home组件返回有效的JSX内容,示例如下:

import { View, Text, StyleSheet } from 'react-native';

export default function Home() {
  return (
    <View style={styles.container}>
      <Text>这是我的第一个Expo Router页面</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#fff',
  },
});

3. 确认_layout.js的配置正确性

确保Stack路由配置正确,示例如下:

import { Stack } from 'expo-router';

export default function RootLayout() {
  return (
    <Stack>
      <Stack.Screen name="index" options={{ title: '首页' }} />
    </Stack>
  );
}

验证修复

修改完成后,重启Expo开发服务器(如果之前已启动),重新加载App,布局即可正常显示。

内容的提问来源于stack exchange,提问作者hello

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 01:42:01