[Feature Request] Handling multiple <Outlet/> inside component #11512
amBunkowski
started this conversation in
Proposals
Replies: 3 comments 2 replies
-
An // child-route.tsx
export function ChildRoute() {
return (
<>
<Slot id="someId">
// content for slot 1
</Slot>
<Slot id="someId2">
// content for slot 2
</Slot>
</>
)
} Or do you want to configure multiple child routes for the same path but with a You could potentially have different loaders as well. const router = createBrowserRouter([
{
path: "/",
element: <Root />,
loader: rootLoader,
children: [
// multiple children with the same path but different slots.
// You can have different elements and loaders
{
slotId: 'someId',
path: "team", // alternate syntax "team@someId"
element: <ElementForSomeId />,
loader: teamLoader,
},
{
slotId: 'someId2',
path: "team", // alternate syntax "team@someId2"
element: <ElementForSomeId2 />,
loader: teamLoader2,
},
],
},
]); |
Beta Was this translation helpful? Give feedback.
1 reply
-
I've came up with user land solution import { useOutlet } from "@remix-run/react";
import { createContext, use, type ReactNode } from "react";
const ExtraOutletContext = createContext<string>("children");
export function ExtraOutlet(props: {
id: string;
context?: unknown;
}): ReactNode {
return useExtraOutlet(props.id, props.context);
}
export function ExtraOutlets(
props: Record<"children" | (string & {}), ReactNode>,
): ReactNode {
const id = use(ExtraOutletContext);
return props[id];
}
export function useExtraOutlet(id: string, context?: unknown): ReactNode {
const outlet = useOutlet(context);
return <ExtraOutletContext value={id}>{outlet}</ExtraOutletContext>;
} Usage looks like this: // root.tsx
export function Root() {
return (
<>
<ExtraOutlet id="appBar" />
<main>
<Outlet />
</main>
<ExtraOutlet id="footer" />
</>
);
} // routes.tsx
const router = createBrowserRouter([
{
path: "/",
element: <Root />,
loader: rootLoader,
children: [
{
path: "team",
element: (
<ExtraOutlets appBar={<AppBar />}>
<ElementForSomeId />
</ExtraOutlets>
),
loader: teamLoader,
},
],
},
]); |
Beta Was this translation helpful? Give feedback.
1 reply
-
Similar problem to #9601 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
It would be greate to see support for current setups:
<> <TableContainerStl> <Outlet id="someId"/> </LicencesTableContainerStl> <Outlet id="someId2" /> </>
Beta Was this translation helpful? Give feedback.
All reactions