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

parameterized route and absolute routes in combination supported? #3521

Closed
pke opened this issue Jun 7, 2016 · 2 comments
Closed

parameterized route and absolute routes in combination supported? #3521

pke opened this issue Jun 7, 2016 · 2 comments

Comments

@pke
Copy link

pke commented Jun 7, 2016

I have component that renders a map with a list of markers depending on :scope and potentially a detail defined by :id.

<Route path="/:scope" component={MapComponent}>
  <Route path=":id" component={MapComponent}>
</Route>

it seems that nesting 2 MapComponent like this is allowed by the router and does not lead to the MapComponent rendered twice.

Now, the problem is I want to have some additional routes being rendered on top of MapComponent, whether or not an :id was specified.

So paths like:
/cities
/cities/1
/about

should all be possible and the MapComponent should be rendered beneath the About component.
Question is: How would the routes have to be nested and are there some kind of default values so that /about would fill up the missing route params of MapComponent with some defaults like :scope="cities" && :id=""

@timdorr
Copy link
Member

timdorr commented Jun 8, 2016

First, absolute routes are going away (#3319).

You've got a subtle misunderstanding of how routes nest. For the /cities/1 url, what essentially gets rendered is:

<MapComponent>
  <MapComponent />
</MapComponent>

or in other words:

<MapComponent children={<MapComponent>}>

So, you've got an odd route combination. The MapComponent isn't rendered twice because it's not rendering this.props.children. This would be a better config:

<Route path="/:scope">
  <IndexRoute  component={MapComponent} />
  <Route path=":id" component={MapComponent} />
</Route>

You only get the id param because we pass the fully parse params to every route component. So, it's a happy accident all of this works. But it would be better with a proper <IndexRoute>.

@timdorr timdorr closed this as completed Jun 8, 2016
@pke
Copy link
Author

pke commented Jun 8, 2016

Thanks Tim, I always suspected something looks fishy with the routes. Copied that schema somewhere from the web.
Sad to see absolute routes to go away. I found them quite easy to spot in the config

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

No branches or pull requests

2 participants