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