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

使用Expo Router路由时遇“No route named 'register' exists”错误求助

Expo Router路由配置错误排查

问题描述

使用Expo React开发移动应用时,配置Expo Router路由出现以下错误:

[Layout children]: No route named "register" exists in nested children: ["(auth)", "(tabs)", "[...missing]", "auth/index", "modal", "_sitemap"]

相关代码

app/_layout.tsx

import FontAwesome from "@expo/vector-icons/FontAwesome";
import {
  DarkTheme,
  DefaultTheme,
  ThemeProvider,
} from "@react-navigation/native";
import { useFonts } from "expo-font";
import { SplashScreen, Stack } from "expo-router";
import { useEffect } from "react";
import { useColorScheme } from "react-native";

export {
  // Catch any errors thrown by the Layout component.
  ErrorBoundary,
} from "expo-router";

export const unstable_settings = {
  // Ensure that reloading on `/modal` keeps a back button present.
  initialRouteName: "(tabs)",
};

export default function RootLayout() {
  const [loaded, error] = useFonts({
    SpaceMono: require("../assets/fonts/SpaceMono-Regular.ttf"),
    ...FontAwesome.font,
  });

  // Expo Router uses Error Boundaries to catch errors in the navigation tree.
  useEffect(() => {
    if (error) throw error;
  }, [error]);

  return (
    <>
      {/* Keep the splash screen open until the assets have loaded. In the future, we should just support async font loading with a native version of font-display. */}
      {!loaded && <SplashScreen />}
      {loaded && <RootLayoutNav />}
    </>
  );
}

function RootLayoutNav() {
  const colorScheme = useColorScheme();

  return (
    <>
      <ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
        <Stack>
          <Stack.Screen name="(tabs)" options={{ headerShown: false }} />
          <Stack.Screen name="(auth)" options={{ headerShown: false }} />
          <Stack.Screen
            name="register"
            options={{ presentation: "fullScreenModal" }}
          />
          <Stack.Screen name="modal" options={{ presentation: "modal" }} />
        </Stack>
      </ThemeProvider>
    </>
  );
}

(auth)/_layout.tsx

import { Stack } from "expo-router";

export default function AuthLayout() {
  return (
    <>
      <Stack>
        <Stack.Screen name="index" options={{ headerShown: false }} />
        <Stack.Screen name="register" />
      </Stack>
    </>
  );
}

问题原因与修复

核心问题

你在根布局的Stack里直接声明了register路由,但register是(auth)目录下的嵌套子路由,根布局只能识别顶级路由(比如(tabs)、(auth)这类分组路由),无法直接引用嵌套在分组里的子路由。

修复步骤

  1. 删除根布局中的register路由
    在RootLayoutNav的Stack组件中,移除这一段代码:

    <Stack.Screen
      name="register"
      options={{ presentation: "fullScreenModal" }}
    />
    
  2. 按需配置auth布局中的register路由样式
    如果需要register页面以全屏弹窗形式展示,把配置移到(auth)/_layout.tsx里:

    <Stack.Screen 
      name="register" 
      options={{ presentation: "fullScreenModal" }} 
    />
    

规则说明

Expo Router是基于文件系统的路由,(auth)/register.tsx属于(auth)分组的子路由,所有和它相关的路由配置都应该放在(auth)/_layout.tsx中,根布局只负责管理顶级的路由分组。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 18:47:08