Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 使用参数响应路由器发送URL_Reactjs - Fatal编程技术网

Reactjs 使用参数响应路由器发送URL

Reactjs 使用参数响应路由器发送URL,reactjs,Reactjs,您好,我刚刚创建了一个组件,在其中我得到了一个产品,我有描述值​​etc每个产品都有一个代码,页面url是/products我如何将url与 / product / category/codproduct 产品代码中的其他参数总是会有所不同 我可以用redux做这个吗 <Router> <Route exact path='/' component={Home} /> <Route path='/product/(category/

您好,我刚刚创建了一个组件,在其中我得到了一个产品,我有描述值​​etc每个产品都有一个代码,页面url是/products我如何将url与

/ product / category/codproduct
产品代码中的其他参数总是会有所不同

我可以用redux做这个吗

    <Router>
      <Route exact path='/' component={Home} />
      <Route path='/product/(category/codproduct)' component={description} />
      <Route path='/settings' component={Settings} />
    </Router >

您可以发送带有react router(如产品id)的道具,在您的产品页面中执行api调用获取产品数据

let {productId, category} = ths.state
    <Route
      path='/dashboard'
      component={() => <ProductPage productId={product} category={category/>}
    />
let{productId,category}=th.state
}
/>

在路线中定义参数

      <Router>
          <Route exact path='/' component={Home} />
          <Route path='/product/:category/:codproduct' component={description} />
          <Route path='/settings' component={Settings} />
        </div>
      </Router>
如果您匹配的是准确的url

this.props.category and this.props.codproduct
    <Router>
      <Switch>
        <Route exact path='/' component={Home} />
        <Route path='/product/:category/:codproduct' render={(props) => {
          <Description category={props.match.params.category} codproduct={props.match.params.codproduct} />
        }} />
        <Route path='/settings' component={Settings} />
      </Switch>
    </Router >
import {Switch} from 'react-router-dom'
this.props.category and this.props.codproduct