简体   繁体   中英

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. 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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM