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

Remix V2路由:非布局嵌套时子路由如何访问父路由Loader数据?

在Remix V2中无布局嵌套时共享父路由Loader数据的方案

场景背景

我在Remix应用里遇到这样的需求:父路由有概览UI,对应的子路由需要复用父路由Loader加载好的数据,但明确不需要使用布局嵌套(也就是不用<Outlet />)。

常规嵌套路由结构下:

account.invoices.tsx
account.invoices.due.tsx
account.invoices.paid.tsx

due和paid子路由通过<Outlet />嵌套在account.invoices下,能直接访问父路由Loader的数据。

但我常用带尾部下划线的路由命名来取消布局嵌套,结构如下:

account.invoices.tsx
account.invoices_.due.tsx
account.invoices_.paid.tsx

这种结构下,account.invoices和account.invoices_是完全独立的路由,导致due和paid子路由无法获取account.invoices的Loader数据。

当前尝试的解决方案与疑问

我想到的解决办法是重构路由,新增一个仅包含Loader的中间路由和索引路由,结构变成:

account.invoices._loader.tsx
account.invoices._loader._index.tsx
account.invoices._loader.due.tsx
account.invoices._loader.paid.tsx

但这样会让路由结构变得更复杂。想问:这是不是Remix社区的常规做法?有没有更惯用的解决方案?

注:这个问题和我之前关于v1路由的问题类似,但更聚焦于Remix V2中account.invoices与account.invoices_这类路由的Loader行为差异。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 00:22:19