我正在使用,MemoryRouter
并且我不希望浏览器将鼠标悬停在时显示完整链接(在左下角)Link
。
<Link to="/somepath" />
在to
属性中使用函数似乎无效。
我知道它在其中包装了<a>
标签,但href
即使在中传递了函数,它仍然会使用to
。有什么办法实现呢?
如果您不想显示该链接onHover
,请考虑以编程方式使用onClick
而不是使用来更改页面Link
,因为它们显示为a
具有其自身href
属性的普通标记,从而暴露了URL。
这是文档的摘录
import { useHistory } from "react-router-dom";
function HomeButton() {
let history = useHistory();
function handleClick() {
history.push("/home");
}
return (
<button type="button" onClick={handleClick}>
Go home
</button>
);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句