[英]remix.run meta, getting info from parent routes
I have a nested route in Remix that I want to have *mostly the same meta information as its parent.我在 Remix 中有一个嵌套路由,我希望它具有 * 与其父级几乎相同的元信息。 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.我假设如果没有从路由中导出
meta
属性,那么 Remix 将 go 沿着链向上直到它到达根。
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
.我检查了
meta
调用可用的参数,虽然有parentsData
- 这只是来自父loader
函数的数据,而不是父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?有什么我遗漏的东西,或者有什么约定可以让我完成这个吗?
Unfortunately Remix does not provide the actual meta
response from parent to child routes.不幸的是,Remix 没有提供从父路由到子路由的实际
meta
响应。 If you need customized meta values, then you should return those from the loaders directly.如果您需要自定义元值,那么您应该直接从加载器返回这些值。
You could use parentsData
from all the parent loaders, adding any meta info in there, not direct solution but a work around.您可以使用所有父加载器中的
parentsData
,在其中添加任何元信息,而不是直接解决方案,而是解决方法。
docs: https://remix.run/docs/en/v1/api/conventions文档: https://remix.run/docs/en/v1/api/conventions
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.