R
R
rsoinvi2018-07-18 22:03:45
React
rsoinvi, 2018-07-18 22:03:45

How to do nesting in react router?

Tell me how to work with nested pages in the router? I want the content inside the home to be displayed by the link, that is, like this home / services.
home and contacts work, and service returns a blank page
Code for the service component

class MainBar extends Component {
  render(){
    return(
      <div className="center_container">
        <Route path="/service" component={Service} />
      </div>
    )
  }
}

The structure is like this:
/home
   /Services
/Contacts

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2018-07-18
@rsoinvi

<Route path="/home/services" component={Service} />

J
jondoeonoe, 2018-07-18
@jondoeonoe

Have you looked at the log in the console, errors? You can generally fill in here in the sandbox, through codesandbox the same, it will be faster.
And on topic. You just write like "Render this component to me if there is a /service path", of course it will not be able to go to home/service, it will only work on the path /service
Look in the match.url dock
https://reacttraining.com/react -router/web/example... An example is in the const Topics doc

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question