-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: Named Outlets #8446
Comments
looks like there is a way to do it https://reactrouter.com/docs/en/v6/faq#how-do-i-nest-routes-deep-in-the-tree |
having a separate Routes tree can accomplish this I guess. But it comes with a lot of baggage too. Let's say a component using a react-router hook rendered in the different Routes instance trees would get different output. I would prefer having one Routes instance for the entire app as much as possible. |
Looking at the source, looks like If it does, then I guess it's a bug? 😅 |
Oh ok. I might be wrong then. Will try it out. |
As pointed out, you can just continue to nest your Route's deeper or use multiple levels of Routes. Either is fine and should work the same at the component level. |
Hi everybody, Any idea? For now I'll leave the less important <Routes> element in place. Thanks in advance. |
Is there any plan to support that? I would like to place some extra content in the menu of the parent route but still to be controlled by the child route. I did something like that using React portals but it's not working well with SSR. I guess the problem could be using it with Remix and actually how to decide what to render and where. With pure React Router it should be easy as you have full control. However, with Remix and file convention it becomes tricky. So I thought that you could actually do something like that: export default function AdminUsersPage() {
const { users } = useLoaderData<typeof loader>();
return (
<>
<RenderToOutlet>
<Users users={users} />
</RenderToOutlet>
<RenderToOutlet name="menu">
<UsersFilter users={users} />
</RenderToOutlet>
</>
);
} Not providing the In the meantime, I will handle it differently but would be great to have support for named outlets. Hope, that this feature was not abandoned or some other solution is in the works. |
Actually I achieved the same effect with // Parent
type FilterContext = {
setFilter: (filter: React.ReactNode | null) => void;
};
export default function ParentPage() {
const [filter, setFilter] = React.useState<React.ReactNode | null>(null);
return (
<div className="flex flex-row w-full h-full">
<div className="flex-none">
<Menu/>
{filter}
</div>
<div className="flex-1">
<Outlet context={{ setFilter } satisfies FilterContext} />
</div>
</div>
);
}
export function useFilter() {
return useOutletContext<FilterContext>();
} // Child
export default function ChildPage() {
const { setFilter } = useFilter();
React.useEffect(() => {
setFilter(<ChildPageFilter />);
return () => setFilter(null);
}, [setFilter]);
return (
<div>Content</div>
);
} And it works great with SSR, no hacks with portals required. I love Remix even more now :D |
Great work! It is unfortunate that this hinges in a |
…ilable when building stack trace (#8446) Co-authored-by: Matt Brophy <matt@brophy.org>
What is the new or updated feature that you are suggesting?
Currently we can only render one component for a given url using
then we can decide where this content gets rendered in the subtree using Outlet.
There should be a guide / recipe / official component which shows how different subtrees can render a specific component on the same route maybe by matching via name string.
I've made a POC on StackBlitz. It works by injecting a name to the element returned by useOutlet. And then using the name in NamedRoutes component to render specific component.
This is the API-
Why should this feature be included?
<Route />
deep in the tree. SinceRoute
now needs to be at top level, that approach is not possible so an alternative is needed.The text was updated successfully, but these errors were encountered: