简体   繁体   中英

how to change a component without rendering the other component in reactjs and react-router-dom

i have three component Header,Sidebar,and another one is the center . the center fetch data(all datas-post). In each post there will be a button to see present full post . now the full-post component will be replacing the all post-component. I dont want to render all other component. Just want to render the full-post component.Now How can I do this. My app.js containing the three main component

export default class App extends React.Component{
  constructor(props){
    super(props);
  }
  render(){
    return (
      <ApolloProvider client = {client} >
        <div >
          <div className="row">
            <SideBar store={store} />
            <Center store={store} />
            <RightSlidePanel store={store}/>
          </div>
        </div>
      </ApolloProvider>
    )
  }
}

center.js component

  render(){

    return (
      <Provider store = {this.store}>
        <div className="center-bar nine columns ">
          <div className="row">
              <CenterHeader />
              <PostContent />
              <RightSide />
          </div>
        </div>
      </Provider>
    )

now all the post are in postContent component . Now A component postdetail will be there which when a button will be click it will replace the postContent in this center component

You would need a route for each post that is rendered via url parameters. Notice :id for rendering a specific post. When that post is reached it can fetch its needed data as well.

  render () {
    return (
      <Switch>
        <Route
          exact
          path={'/posts'}
          render={() => {
            return (
              <BlogSummaryList
                posts={this.state.blogPosts}
              />
            )
          }}
        />
        <Route
          exact
          path={'/posts/:id'}
          component={BlogPost}
        />
    )
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM