I have create a project for blogging app and I was trying to call the loader function to a components of layouts but couldn't run the loader function as the function runs properly in routes path. I am not sure if I am using the loader correctly or not. My use case is:
I have a folder structure as below:
app
|-> routes
| |-> home.tsx
|-> components/layout
| |-> index.tsx
| |-> header.tsx
|-> routes.ts
// and other files related to the project
My component/layout file contains the layout structure of the application like header footer and so on. And in my components/layout/header.tsx file I want to call the loader is this possible?
My routes.ts contains the code as below:
import { type RouteConfig, index, layout } from "@react-router/dev/routes";
export default [
layout(
"components/layout/index.tsx", [
index("routes/home.tsx")
]
)
] satisfies RouteConfig;
If this is not possible let me know how can I achieve the loader call in header.tsx file because I want to call the loader function to get the dynamic menus from the backend, which I should display in the header menu.