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

Expo Router页面无法找到问题:从[venue]跳转至offer/[offer]失败

问题描述

文件结构包含app/venue/[venue]、app/offer/[offer]等路径,当前处于venue/[venue]页面,尝试导航至offer/[offer]页面,用了两种router.push写法:

router.push({
  pathname: "/offer/",
  params: {
    id: id,
  },
});

router.push({
  pathname: `/offer/${id}`,
  params: {
    id: id,
  },
});

结果都弹出「Page could not be found」错误。

相关布局代码如下:

OFFER/_LAYOUT

return (
  <Stack.Screen
    name="[offer]"
    options={{
      headerTitle: "",
      presentation: "modal",
      headerRight: () => (
        <TouchableOpacity onPress={() => router.back()}>
          <Icon name="close-line" size={24} color={textColor} />
        </TouchableOpacity>
      ),
    }}
  />
);

VENUE/_LAYOUT

return (
    <Stack
      screenOptions={{
        headerStyle: {
          backgroundColor: backgroundColor,
        },
        headerTintColor: textColor,
      }}
    >
      <Stack.Screen
        name="[venue]"
        options={{
          headerShown: false,
          headerTransparent: true,
          headerTitle: "",
          headerLeft: () => (
            <TouchableOpacity onPress={() => router.back()}>
              <Icon name="arrow-left-line" size={24} color={textColor} />
            </TouchableOpacity>
          ),
        }}
      />
    </Stack>
);
解决方案

1. 修正路由参数和路径写法

你的动态路由页面是offer/[offer],参数名必须和路由文件名里的[offer]一致,而不是id。同时路径要正确指向动态路由:

// 写法一:通过pathname和params传参
router.push({
  pathname: "/offer/[offer]",
  params: {
    offer: id, // 参数名对应[offer]
  },
});

// 写法二:直接拼接完整路径(无需额外传params)
router.push(`/offer/${id}`);

2. 补全Offer布局的外层Stack标签

当前OFFER/_LAYOUT代码缺少外层的<Stack>包裹,这会导致路由无法正确识别页面结构,修改后的完整布局应该是:

import { Stack } from 'expo-router';

export default function OfferLayout() {
  return (
    <Stack>
      <Stack.Screen
        name="[offer]"
        options={{
          headerTitle: "",
          presentation: "modal",
          headerRight: () => (
            <TouchableOpacity onPress={() => router.back()}>
              <Icon name="close-line" size={24} color={textColor} />
            </TouchableOpacity>
          ),
        }}
      />
    </Stack>
  );
}

3. 确认路由文件名匹配

确保app/offer/目录下的动态页面文件名为[offer].js(或.tsx),和布局中name="[offer]"完全对应,大小写也要一致。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 00:04:51