T
TanStack13mo ago
conscious-sapphire

Getting loader data from parent route

So I see that it's possible to get loader data from parent routes but I have some questions. 1. In the component, is this the only way to get data from parent route AND current route?
const { projects } = Route.useLoaderData();
const { team } = useLoaderData({ from: '<parent-route>' });
const { projects } = Route.useLoaderData();
const { team } = useLoaderData({ from: '<parent-route>' });
2. In meta how do I access this loader data from parent route?
// only has the data from this route's loader but I would like to access `team` as well
meta: ({ loaderData: {projects} }) => {
return [
{
title: 'Projects',
},
];
},
// only has the data from this route's loader but I would like to access `team` as well
meta: ({ loaderData: {projects} }) => {
return [
{
title: 'Projects',
},
];
},
2 Replies
rival-black
rival-black13mo ago
about 1) you can use useParentMatches as well about 2) you can access matches in meta as well
meta: ({matches,match}) => {
const parentMatch = matches[match.index - 1]
const parentLoaderData = parentMatch.loaderData
return []
},
meta: ({matches,match}) => {
const parentMatch = matches[match.index - 1]
const parentLoaderData = parentMatch.loaderData
return []
},
conscious-sapphire
conscious-sapphireOP13mo ago
Ah cool, thanks! I wasn’t really sure how to use those properties. Will give it a try

Did you find this page helpful?