Javascript 如何在react路由器中捕获URL的动态部分
我有一个调用Javascript 如何在react路由器中捕获URL的动态部分,javascript,html,reactjs,react-router,react-router-dom,Javascript,Html,Reactjs,React Router,React Router Dom,我有一个调用PriceWithId函数的路径 使用这个.props.match.params.pId 或带有功能部件 const PriceWithID = (props) => { let pId = props.match.params.pId return( <Price image={IMGS.filter((i)=>(i.id === parseInt(pId))[0]}/> );
PriceWithId
函数的路径
使用这个.props.match.params.pId
或带有功能部件
const PriceWithID = (props) =>
{
let pId = props.match.params.pId
return(
<Price image={IMGS.filter((i)=>(i.id === parseInt(pId))[0]}/>
);
}
constpricewithid=(道具)=>
{
设pId=props.match.params.pId
返回(
(i.id==parseInt(pId))[0]}/>
);
}
使用此.props.match.params.pId
或带有功能部件
const PriceWithID = (props) =>
{
let pId = props.match.params.pId
return(
<Price image={IMGS.filter((i)=>(i.id === parseInt(pId))[0]}/>
);
}
constpricewithid=(道具)=>
{
设pId=props.match.params.pId
返回(
(i.id==parseInt(pId))[0]}/>
);
}
前面的答案可以通过以下方式进行改进:
constpricewithid=({match})=>
{
返回(
(i.id==parseInt(match.params.pId,10))[0]}/>
);
}
前面的答案可以通过以下方式进行改进:
constpricewithid=({match})=>
{
返回(
(i.id==parseInt(match.params.pId,10))[0]}/>
);
}
谢谢@燃烧酒精谢谢@燃烧酒精