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

Expo开发构建中路由跳转至+not-found页面,但Expo Go中正常工作的问题求助

Expo开发构建中路由跳转至+not-found页面,但Expo Go中正常工作的问题求助

我刚上手Expo(说实话React Native也是新手),碰到个挺奇怪的问题:用Android开发构建包的时候,我的栈路由直接就跳到+not-found页面了,但在Expo Go里测试完全正常。现在我有点摸不着头脑,想问问大伙有没有什么排查方向或者解决方案?

先给大家看看我的代码和文件结构:

初始的app/_layout.tsx

import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';
import { useFonts } from 'expo-font';
import { Stack } from 'expo-router';
import { StatusBar } from 'expo-status-bar';
import 'react-native-reanimated';
import { useColorScheme } from '@/hooks/useColorScheme';

export default function RootLayout() {
  const colorScheme = useColorScheme();
  const [loaded] = useFonts({
    SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
  });

  return (
    <ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
      <Stack>
        <Stack.Screen name="(tabs)" options={{ headerShown: false }} />
        <Stack.Screen name="+not-found" />
      </Stack>
      <StatusBar style="auto" />
    </ThemeProvider>
  );
}

初始的app/(tabs)/_layout.tsx

import { Tabs } from 'expo-router';
import React from 'react';
import { Platform } from 'react-native';
import { HapticTab } from '@/components/HapticTab';
import { IconSymbol } from '@/components/ui/IconSymbol';
import TabBarBackground from '@/components/ui/TabBarBackground';
import { Colors } from '@/constants/Colors';
import { useColorScheme } from '@/hooks/useColorScheme';

export default function TabLayout() {
  const colorScheme = useColorScheme();
  console.log("inner_route");
  
  return (
    <Tabs
      initialRouteName='Map'
      screenOptions={{
        tabBarActiveTintColor: Colors[colorScheme ?? 'light'].tint,
        headerShown: false,
        tabBarButton: HapticTab,
        tabBarBackground: TabBarBackground,
        tabBarStyle: Platform.select({
          ios: {
            // Use a transparent background on iOS to show the blur effect
            position: 'absolute',
          },
          default: {},
        }),
      }}>
      <Tabs.Screen
        name="Map"
        options={{
          title: 'Map',
          tabBarIcon: ({ color }) => <IconSymbol size={28} name="map.fill" color={color} />,
        }} />
      <Tabs.Screen
        name="Connection"
        options={{
          title: 'Connection',
          tabBarIcon: ({ color }) => <IconSymbol size={28} name='antenna.radiowaves.left.and.right.circle' color={color} />,
        }} />
    </Tabs>
  );
}

初始文件结构

app/
├── _layout.tsx
├── +not-found.tsx
└── (tabs)
    ├── Connection.tsx
    ├── _layout.tsx
    └── Map.tsx

我已经做的尝试

我看到Expo Router的规范里建议文件名用小写,所以我把Map.tsx改成了map.tsx,Connection.tsx改成了connection.tsx,同时更新了(tabs)/_layout.tsx里的路由配置:

修改后的app/(tabs)/_layout.tsx路由部分

<Tabs
  initialRouteName='map'
  screenOptions={{
    tabBarActiveTintColor: Colors[colorScheme ?? 'light'].tint,
    headerShown: false,
    tabBarButton: HapticTab,
    tabBarBackground: TabBarBackground,
    tabBarStyle: Platform.select({
      ios: {
        // Use a transparent background on iOS to show the blur effect
        position: 'absolute',
      },
      default: {},
    }),
  }}>
  <Tabs.Screen
    name="map"
    options={{
      title: 'Map',
      tabBarIcon: ({ color }) => <IconSymbol size={28} name="map.fill" color={color} />,
    }} />
  <Tabs.Screen
    name="connection"
    options={{
      title: 'Connection',
      tabBarIcon: ({ color }) => <IconSymbol size={28} name='antenna.radiowaves.left.and.right.circle' color={color} />,
    }} />
</Tabs>

修改后的文件结构

app/
├── _layout.tsx
├── +not-found.tsx
└── (tabs)
    ├── connection.tsx
    ├── _layout.tsx
    └── map.tsx

但做完这些修改之后,在Android开发构建里还是会直接跳转到+not-found页面,Expo Go里依旧正常。现在我真的有点卡壳了,有没有大佬能给点提示?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.08 12:30:30