【发布时间】:2021-04-27 15:16:14
【问题描述】:
我有 2 个具有不同路径的 App 逻辑部分,我需要知道用户去哪里。我是这样做的:
this.props.history.listen((location, action) =>
{
if (action === "PUSH")
{
const { modeType } = this.props;
if ((modeType === first && secondPathes.includes(location.pathname))
|| (modeType === second && firstPathes.includes(location.pathname)))
{
// some logic
}
}
});
但它不适用于带有参数的路径:"/customers/1/profile" != "/customers/:id/profile"。如何正确比较路径?
【问题讨论】:
标签: reactjs path routes comparison