Hello! Let me explain without further a due:
Assuming routes set up in this way:
const routes = [
layout('api/middleware.tsx', [
index('routes/index.tsx'),
route('/api/test', 'api/test.tsx'),
]),
];
Where api/middleware.tsx uses an Outlet to pass data down to any route that may need the data:
export const loader = () => {
return { hello: 'world' };
};
const Middleware = () => {
const data = useLoaderData<typeof loader>();
return <Outlet context={data} />;
};
export default Middleware;
And routes/index.tsx can use the data from middleware's loader with the outlet's context:
const Index = () => {
const data = useOutletContext();
// this should render something saying {"hello": "world"}
return (
<div>do something with {JSON.stringify(data)}</div>
);
};
export default Index;
Lastly, api/test.tsx is a resource route:
export const loader = () => {
const data = // somehow get `middleware`'s data;
return { ...data, foo: 'bar' };
};
The question is: given api/test.tsx is a nested route within api/middleware.tsx, is there any way that test's loader can access whatever data was returned from api/middleware.tsx?