I have a react application with react-router. I am trying to setup nested routes:
"/" --> home page
"/products" --> products list (child component of home page)
"/products/new" --> new product: child component of products list
What I tried to do so far:
<Route path="/" component="home" >
<Route path="products" component="products" >
<Route path="new" component="products_new" />
</Route>
</Route>
Now in the browser from my default home page, when I hit "/products"
, the products component is loaded and I can see my list of products. But when I hit "products/new"
nothing happens. I get a blank page. If I hit "/new"
(not nested) it works (page product_new is loaded inside its parent).
(this "/products/new"
does not work; this "/new"
works)
I had a look to this question on github Problem with nested routes #687. The solution says:
I discovered my problem. Parent routes are always called. Thats the intent. But child components need to have repeated
<Router.RouteHandler/>
to get rendered.
I cannot understand this solution. What does it mean:
"but child components need to have repeated
<Router.RouteHandler/>
to get rendered"
EDIT1: Here are my components (routers and views):
My routing hierarchy:
<Route path="/" > <IndexRoute component={Home}/> <Route path="products"> <IndexRoute component={Products} /> <Route path="new" component={Products_New} /> </Route> </Route> </Router>
My home component:
<div className="col-lg-12"> <h1>Home page</h1> <hr /> {this.props.children} </div>
My products components:
<div> <div className="col-lg-12"> <h1>Products</h1> </div> <hr /> {this.props.children} </div>
- My product-new component: