Skip to content
Discussion options

You must be logged in to vote

I found the error. My mistake. If I use beforeLoad to expose some data, I should use useRouteContext instead of forwarding useLoaderDate.

the right code would be:

Route

export const Route = createFileRoute({
  component: MainLayout,
  beforeLoad: async () => {
    const loaderData = await rootLoader();
    checkDomainAccess(loaderData.pca, loaderData.publicInfo.allowedDomains);
    return loaderData;
  },
});

Component

const { useRouteContext, useNavigate } = getRouteApi("/_layout");

export default function MainLayout() {
  const navigate = useNavigate();
  const { pca, publicInfo } = useRouteContext();
  ...
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by rhuanbarreto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants