Skip to content
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

Change how we handle index routes with nested components #3326

Closed
taion opened this issue Apr 15, 2016 · 11 comments
Closed

Change how we handle index routes with nested components #3326

taion opened this issue Apr 15, 2016 · 11 comments
Labels

Comments

@taion
Copy link
Contributor

taion commented Apr 15, 2016

Currently we support this syntax:

<Route path="foo" component={A}>
  <Route component={B}>
    <Route component={C}>
      <IndexRoute component={D}>
    </Route>
  </Route>
</Route>

This is a little bit awkward and only works for sync child routes (i.e. it won't work if these child routes were declared via getChildRoutes).

I'd like to propose changing this API up a bit. A few options:

// Nest <IndexRoute> instead of pathless <Route>.
<Route path="foo" component={A}>
  <IndexRoute component={B}>
    <IndexRoute component={C}>
      <IndexRoute component={D}>
    </IndexRoute>
  </IndexRoute>
</IndexRoute>

// Add a nest() or compose() helper, or document it.
<Route path="foo" component={A}>
  <IndexRoute component={nest(B, C, D)} />
</Route>

// Add first-class support for array route components, with above semantics.
<Route path="foo" component={A}>
  <IndexRoute components={[B, C, D]} />
</Route>

If we take out nested routes with absolute path support, this would remove the only other inconsistency to my knowledge between the sync and async child route cases.

@ryanflorence
Copy link
Member

Looks, good, lets hold off on any sort of utils to make the nesting easier.

If we take out nested routes with absolute path support, this would remove the only other inconsistency to my knowledge between the sync and async child route cases.

This is the nail in coffin for me and nested absolute routes.

@taion
Copy link
Contributor Author

taion commented Apr 15, 2016

Should we add support for nesting <IndexRoute> like in the first example? We don't currently support it, but it should be easy to add.

@taion
Copy link
Contributor Author

taion commented Apr 15, 2016

cc @danieljuhl, who added this feature in #2330.

@ryanflorence
Copy link
Member

ryanflorence commented Apr 16, 2016

What does this become?

    <Router history={ history }>
      <Route path='/' component={ App }>
        <Route path='signup' component={ Signup } />
        <Route path='login' component={ Login } />
        <Route component={ ListPage }>
          <Route path='search' component={ Search } />
          <IndexRoute component={ Home } />
        </Route>
        <Route path='*' name='not-found' component={ NotFound } />
      </Route>
    </Router>

@taion
Copy link
Contributor Author

taion commented Apr 16, 2016

Maybe:

<Router history={ history }>
  <Route path='/' component={ App }>
    <IndexRoute component={ ListPage }>
      <IndexRoute component={ Home } />
    </IndexRoute>
    <Route path='signup' component={ Signup } />
    <Route path='login' component={ Login } />
    <Route component={ ListPage }>
      <Route path='search' component={ Search } />
    </Route>
    <Route path='*' name='not-found' component={ NotFound } />
  </Route>
</Router>

There's some duplication, but maybe it's more clear?

This might be a bit of a harebrained idea on my part.

@agundermann
Copy link
Contributor

agundermann commented Apr 16, 2016

Perhaps I misunderstand the intention, but is this really such a problem? Wouldn't it be easier to just use the route components for composition, instead of the router?

const A = (props) => (<B {...props}><C {...props}>{props.children}</C></B>)

@ryanflorence
Copy link
Member

Yeah exactly, that's what I was thinking when I saw the nest thing.

@taion
Copy link
Contributor Author

taion commented Apr 16, 2016

@taurose That's what I was thinking with nest() or compose(), but it's a little bit different when using async-props or react-router-relay or anything where the container wants to look at the route and inject stuff into the route components.

@ryanflorence
Copy link
Member

I think @taurose code would still do that, no?

@taion
Copy link
Contributor Author

taion commented Apr 16, 2016

Doesn't async-props work via a static loadProps method on the component? You couldn't necessarily merge two loadProps static methods without semantic knowledge.

@taion
Copy link
Contributor Author

taion commented May 5, 2016

Given the tepid response here, and that this does legitimately make cases like #3326 (comment) harder, I'm going to close this out for now. The sync/async mismatch may be a non-issue once we resolve #3232 and put async child routes before the code split, anyway.

@taion taion closed this as completed May 5, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants