Routing react pass parameters

One way: by params

Routing table 1.
  <= the Route path '/ Sort /: ID' = {the Sort Component}> </ the Route>
           
2.Link at

  As HTML
  <Link to = { '/ Sort /' + '2'} = activeClassName 'Active'> XXXX </ Link>     
           
  the JS embodiment
  this.props.router.push ( '/ Sort /' + '2')
           
. 3. sort page
  parameter (id) received by this.props.params.id can be passed over

Second way: through query
premise: to be skipped by the other pages, the parameters will be passed over
    Note: do not need to configure the routing table. A routing table as usual: <Route path = '/ sort ' component = {Sort}> </ Route>

At 1.Link
  the HTML embodiment
  <= {{pathname to Link: '/ Sort', Query: {name: 'Sunny'}}}>
          
the JS embodiment
  this.props.router.push ({path: '/ sort ', query : {name: 'Sunny'}})

2.SORT page
  value: this.props.location.query.name

three ways: by state
  with the query almost, but not the same attribute, and the parameters are transmitted encrypted state, query parameter passed is public, in the address bar

At 1.Link
  the HTML manner:
  <= {{pathname to Link: '/ Sort', State: {name: 'Sunny'}}}>
  
  the JS manner:
  this.props.router.push ({pathname: '/ Sort' , State: {name: 'Sunny'}})
  
2.SORT page
  value: this.props.location.state.name

Guess you like

Origin www.cnblogs.com/Ann-web-1/p/11787240.html