remix.run meta,从父路线获取信息
我有一个混音中的嵌套路线,我想拥有与父母相同的元信息。我假设,如果没有meta
属性是从路线导出的,那么混音将沿链条上升,直到它扎根。
但是,情况似乎并非如此。我已经检查了meta
调用的ARG,虽然有parentsdata
- 这只是父loader
函数的数据,而不是父级<代码> meta 。
理想情况下,我想为我的根路线的元素提供如下的元素
export const meta: MetaFunction = (): HtmlMetaDescriptor => ({
title: 'My App',
});
,并且在嵌套路线中可以做以下操作:
export const meta: MetaFunction = (args): HtmlMetaDescriptor => ({
title: `${args.parentsData.title} | My Route`,
})
我缺少一些我缺少的事情,还是一些可以让我完成此操作的惯例?
I have a nested route in Remix that I want to have *mostly the same meta information as its parent. I would assume that if no meta
property is exported from the route, then Remix would go up the chain until it gets to the root.
This does not appear to be the case, however. I have inspected the args available to the meta
call and while there is parentsData
- this is just the data from parent loader
functions, not parent meta
.
Ideally, I'd like to have for my root route's meta something like the following
export const meta: MetaFunction = (): HtmlMetaDescriptor => ({
title: 'My App',
});
and in nested routes be able to do something like the following:
export const meta: MetaFunction = (args): HtmlMetaDescriptor => ({
title: `${args.parentsData.title} | My Route`,
})
Is there something that I'm missing, or some convention that would allow me to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用Remix V2
您绝对可以消耗
loader
和meta
从任何嵌套子路由中同一层次结构中的任何父路由导出。使用
匹配
参数如下所示,您可以获取所有父级数据:在我的情况下,输出是:
从docs( https://remix.run/docs/en/main/route/meta#matches ):
现在,可以使用与子元功能的父元合并并导出的父元可以满足您的要求。这可以通过两种方式完成:
注意:无论如何,您需要从儿童路线中导出新的元数组,
您应该关注文档。他们还具有具有辅助功能的GIST,可以自动单纯的母体元:
With Remix v2
You can definitely consume
loader
andmeta
exported from any parent route in the same hierarchy in any nested child route.Using
matches
paramter as shown below, you can get all your parent data:In my case output was:
From the docs (https://remix.run/docs/en/main/route/meta#matches):
Now your requirement can be satisfied using parent meta merged and exported from child meta function. This can be done in 2 ways:
Note: in any case you need to export the new meta array from child route
You should follow the docs. They have also a gist with helper function to automatically mere parent meta:
不幸的是,混音未提供从父级到子路由的实际
meta
响应。如果您需要自定义的元值,则应直接从加载程序中返回。Unfortunately Remix does not provide the actual
meta
response from parent to child routes. If you need customized meta values, then you should return those from the loaders directly.您可以在所有父母加载程序中使用
parentsdata
,在其中添加所有元信息,而不是直接解决方案,而是解决方案。文档:
https://remix.run/docs/docs/en/en/en/v1/api/api/api/conventions
You could use
parentsData
from all the parent loaders, adding any meta info in there, not direct solution but a work around.docs:
https://remix.run/docs/en/v1/api/conventions