我有這條調用PriceWithId函數的路由<Route path='/collections/:pId' component={PriceWithID} />功能是這樣的const PriceWithID = ({match}) => { let test = Object.entries(match); let test2 = test.filter(([prop])=>(prop === 'params')); let test3 = test2[0][1]; let test4 = Object.values(test3)[0] return( <Price image={IMGS.filter((i)=>(i.id === parseInt(test4,10)))[0]}/> ); }我知道有一個更好的 oneline 方式來實現test4。我使用的方法伴隨著反復試驗。誰能告訴我更好的方法,以便我可以用它替換 parseInt 中的 test4
如何在 React 路由器中捕獲 URL 的動態部分
哈士奇WWW
2023-05-18 10:10:43