React Native (Expo Go) 返回时崩溃

问题描述 投票:0回答:1

目前正在尝试使用 Expo Go 在 React Native 中进行一些路由。我可以通过

useRouter().push()
路由到新页面,但是当返回上一页时,Expo Go 崩溃,没有任何错误消息。

这是源代码:

// index.tsx
import { Button, Text, View } from "react-native";
import { useRouter } from "expo-router";

export default function Index() {
  const router = useRouter();

  return (
    <View
      style={{
        flex: 1,
        justifyContent: "center",
        alignItems: "center",
      }}
    >
      <Text>Edit app/index.tsx to edit this screen.</Text>
      <Button title="Profile" onPress={() => router.push("profile")} />
    </View>
  );
}
// profile.tsx
import { Button, Text, View } from "react-native";
import { useRouter } from "expo-router";

export default function Profile() {
  const router = useRouter();

  return (
    <View
      style={{
        flex: 1,
        justifyContent: "center",
        alignItems: "center",
      }}
    >
      <Text>Edit app/index.tsx to edit this screen.</Text>
      <Button title="Profile" onPress={() => router.back()} />
    </View>
  );
}
// _layout.tsx

import { Stack } from "expo-router";

export default function Layout() {
  return <Stack />;
}

源代码最初是使用

npx create-expo-app projectName
创建的。我正在 iOS 设备上运行 Expo Go。在网络版本上,路由似乎可以工作,因此我假设在 iOS 设备上使用 Expo Go 存在问题,但我不确定。

如有任何帮助,我们将不胜感激,谢谢!

react-native expo expo-router expo-go
1个回答
0
投票

我在使用 Expo Go 时遇到了同样的问题。当我尝试在 Snack 中重现问题时,一切正常。似乎是最新版本的问题。几天前,有人也在 reddit 上发布了相关内容:https://www.reddit.com/r/expo/comments/1cp4ax5/expo_go_crashing/

© www.soinside.com 2019 - 2024. All rights reserved.