Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.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
Javascript 如何在react路由器中捕获URL的动态部分_Javascript_Html_Reactjs_React Router_React Router Dom - Fatal编程技术网

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]}/>
);

}
谢谢@燃烧酒精谢谢@燃烧酒精