当我正在使用反应时,我尝试从我的页面获取当前路径。我的想法是为每个页面创建规则,因为我的应用程序需要这个。
在第1个示例中,我创建了一个内联组件并且工作正常!
ecs-agent
我有正确的路径! (示例: / test / john)
但是,我不是这样使用的,我无法理解当我在真实组件中时如何重现 {match} ,如下所示:
const names = A.map((obj) => {
if (obj.user) {
return obj.user.firstname;
}
});
我想,仍在阅读当前路径,在获取此信息后,我将使用我的代码创建一些条件。
例如: localhost:3000 / test / username - 路径应为: test / username
答案 0 :(得分:0)
match
道具只传递给<Route />
中直接指定的组件,因此TestLink
的子组件必须明确地赋予match
道具。
<Route path="/test/:username" component={TestLink} />
const TestLink = ({match}) => {
console.log(match.url);
// pass the `match` prop to `CustomComponent`
return <CustomComponent match={match} />;
}