react-router icon indicating copy to clipboard operation
react-router copied to clipboard

[Docs]: missing documentation on route children

Open Jernik opened this issue 3 years ago • 12 comments

What version of React Router are you using?

v6.4

Steps to Reproduce

Go to https://reactrouter.com/en/main/route/route#children See that there is a big TODO on a core concept Shrug and guess you'll have to dig into the source code to figure out the answer to your question.

Expected Behavior

Documentation to exist when I look for it

Actual Behavior

There is just a TODO from 6 months ago from this PR: https://github.com/remix-run/react-router/pull/8937

for a little more context, my questions are: With nested routes, how do I have a "default" child for the <Outlet />, and what is the recommended way to get route parameters into child components? Should I just use the useParams hook?

Jernik avatar Nov 30 '22 18:11 Jernik

I have figured out the answers to my questions, but my complaints about the missing sections in the docs still stand

Jernik avatar Nov 30 '22 18:11 Jernik

I'm having issues as well and looked for documentation to verify if I'm doing something wrong. Is there an ETA on the addition?

martavis avatar Dec 05 '22 19:12 martavis

I have spent a couple hours figuring out how nested routes work juste because no mention of the Outlet component is made in the createBrowserRouter docs. I would advocate for a simple mention in the section where nested routes are described.

jeremiedubuis avatar Jan 24 '23 16:01 jeremiedubuis

Agreed. Surprised such an essential aspect of routing is completely missing from the docs. Definitely less tempted to try Remix seeing how the docs for the main react-router library are maintained.

sgarcia-dev avatar Feb 08 '23 21:02 sgarcia-dev

This issue has been automatically marked stale because we haven't received a response from the original author in a while 🙈. This automation helps keep the issue tracker clean from issues that are not actionable. Please reach out if you have more information for us or you think this issue shouldn't be closed! 🙂 If you don't do so within 7 days, this issue will be automatically closed.

github-actions[bot] avatar Apr 17 '23 21:04 github-actions[bot]

There is still a todo on this section. This issue is not stale.

Jernik avatar Apr 17 '23 21:04 Jernik

It would be nice for the docs to be more detailed and discuss best practices, but until then I've found the React Router in Depth series (not my videos) to be helpful for less senior devs to at least pick up the basics (especially video #4).

camchardukian avatar Jun 18 '23 15:06 camchardukian

It's not just "more" detail though, it's a fundamental part of nesting, no? Like the OP, I'm still wondering how to make a child a default.

Definitely puts me completely off even trying Remix.

*Edit:

Make the default child's path '/' like the parent.

const router = createBrowserRouter([
  {
    path: "/",
    element: <AppLayout />,
    errorElement: <ErrorMessage />,

    children: [
      {
        path: "/",
        element: <Test />,
      },
      {
        path: "typescript",
        element: <Test2 />,
      },
    ],
  },
]);

NickWoodward avatar Jul 17 '23 16:07 NickWoodward

Hi, @brophdawg11 @ryanflorence if anyone is not working on this issue then can I try to write docs for the children prop of the Route element.

girishsontakke avatar Aug 26 '23 15:08 girishsontakke

Documentation is hard! We're doing some major docs overhauls in Remix at the moment and I expect those ideas will make it back into React Router as well once it's completed and Remix v2 is out.

Most of the information asked in this thread is in the docs somewhere today but potentially missing some cross-links (and maybe that's all we need for the children TODO for now). If folks want to help full in some blanks and/or cross-links in the meantime it would be appreciated!

Here's some of the current areas that might benefit from being cross-linked to:

  • The Tutorial is the best place to start to get an understanding of the basic concepts. It has sections on Nested Routes and Outlet.
  • The Main Concepts section also contains a section on Outlets.
  • The Overview section talks about Nested Routes but could probably use a small paragraph at the end on the need for Outlet in the parent route components.
  • Index Routes are covered in the Tutorial and the Main Concepts docs and also on the Route component docs.

brophdawg11 avatar Aug 28 '23 16:08 brophdawg11

An FAQ would also be helpful. I looked there first. A good question would be:

Q: Why does nested routes use <Outlet/> instead of props.children?

Also actually looking for the answer. Has been asked:

  • https://github.com/remix-run/react-router/discussions/8692

Pyrolistical avatar Nov 21 '23 04:11 Pyrolistical