Skip to content Skip to sidebar Skip to footer

Using Nested Routes With React-route

I have a few pages in my app that have their own menus, besides of course the main menu. I wish at every time that the sub-menu is clicked to render a different component. I was t

Solution 1:

Based on what you've show as your route config, things looks sort of okay, but you haven't shown your Help Menu links. I suspect that along with the child route, is what is giving you issues:

<Routepath="help"component={Help}><Routepath="help/:helpOption"component={HelpPanel}/></Route>

The component for each :helpOption should be that options component. So if you had a component called HelpOptionOne you would do this instead:

<Routepath="help"component={HelpPanel}><Routepath="help/:helpOption"component={HelpOptionOne}/></Route>

If building a link for the helpOption it would look like this:

<Link to="/help/help/optionOne">Option 1</Link>

which is probably not what you want, but if you built the href that way, it would work. What you might want is:

<Routepath="help"component={HelpPanel}><Routepath="/:helpOption"component={HelpOptionOne}/></Route>

which would then get your

<Link to="/help/optionOne">Option 1</Link>

Child routes take on their parent route in their path. You just have to remember that. This is a good part of the documentation to read.

Post a Comment for "Using Nested Routes With React-route"