Skip to content

Question about Remix Route Layout and Outlet Content. #140

Answered by kiliman
ttizze asked this question in Q&A
Discussion options

You must be logged in to vote

When I typically need some one-off or custom feature for a specific route, I generally reach for Remix handle https://remix.run/docs/en/main/route/handle

In your layout component, use useMatches to find any route handles.

// Layout.tsx
export default function Layout() {
  const SubHeader = useMatches().find(r => r.handle?.SubHeader)?.handle.SubHeader
  
  return (
    <div>
      <header>Header Component</header>
      {SubHeader && <SubHeader />}
      <main>
        <Outlet />
      </main>
      <footer>Footer Component</footer>
    </div>
  );
}

Then in your auth route, simply export a handle with your custom SubHeader component

// routes/auth/route.tsx
export const handle = {
  SubHe…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@ttizze
Comment options

@kiliman
Comment options

Answer selected by ttizze
@ttizze
Comment options

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