React router best practices for nested navigation? : <p>I am building a React application, and using React Router for managing routing. The information architecture of the application can be represented as follows:</p>

<pre><code> - App
     - Projects
         - Project 1
             - Objects
               - Object 1
               - Object 2
               - etc...
             - Collaborators
         - ...
     - Services
     - Users
</code></pre>

<p>The UI of the application would look something like this, when looking at a route such as <code>/#/projects/1/components/1</code></p>

<pre><code>-----------------------------------------------------------
|            | Home &gt; Projects &gt; 0 &gt; Object &gt; 1           |
|  Home      |--------------------------------------------|
|            |                                            |
|  Projects  |   Object 1                                 |
|            |                                            |
|  Services  |   Blah blah blah                           |
|            |                                            |
|  Users     |                                            |
|            |                                            |
-----------------------------------------------------------
</code></pre>

<p>Note that for any given route shown in the information architecture scheme above, the view should be rendered in the body section (where 'Component 1' is rendered in the diagram above).</p>

<p>Now I will describe how I have been wrongly implementing this in React using React Router:</p>

<p>I have been using PlainRoutes to define my routes. Here is a short example of how a route is defined:</p>

<pre><code>const routes = [
    {
        path: '/',
        component: App,
        name: 'Home',
        childRoutes: [
          // /projects
          {
              path: 'projects',
              component: Projects,
              name: 'Projects'
          },
          {
              path: 'projects/:projectid',
              component: ProjectDetails,
              name: 'Project Details',
              childRoutes: [
                  {
                       path: 'objects',
                       component: Objects,
                       name: 'Objects'
                  },
                  {
                      path: 'objects/:objectid',
                      component: ObjectDetails,
                      name: 'Object Details'
                  },
                  {
                      path: 'collaborators',
                      component: Collaborators,
                      name: 'Collaborators'
                  }
              ]
          },
          // /services
          {
              path: 'services',
              component: Services,
              name: 'Services'
          },
          // /users
          {
              path: 'users',
              component: Users,
              name: 'Users'
          }
      ]
   }
];
</code></pre>

<p>which then get fed into the React Router component, like this: <code>&lt;Router routes={routes}&gt;&lt;/Router&gt;</code></p>

<p>Doing this sort of worked. When I would attempt to navigate to:</p>

<p><code>/#/projects</code></p>

<p>I would see the Projects component rendered in the body of the app.</p>

<p>When I would attempt to navigate to:</p>

<p><code>/#/projects/1</code></p>

<p>I would see the ProjectDetail component rendered in the body of the app.</p>

<p>However, when I would attempt to navigate to:</p>

<p><code>/#/projects/1/objects</code></p>

<p>I would still see the ProjectDetail component rendered in the body of the app. I am not sure why the router would just stop when the <code>/projects/:projectid</code> parameter was resolved, and not continue to render components assigned to the <code>/projects/:projectid/objects</code> route.</p>

<p>I think that the problem was that I was using React Router in the wrong way. Child routes are supposed to be physically nested inside their parent components - not just logically nested. At least, I think that is the problem. Clearly, I am a bit confused as to how React Router is intended to be used - especially the concept of <code>childRoutes</code>.</p>

<p>The question then is - how to use React Router to give the application the hierarchical structure that I am seeking, as outlined above? I want the router to be aware of the deeply nested structure of the application (for things like breadcrumbs and navigation), but I don't want to physically nest the components inside one another. What are best practices here?</p>
