简体   繁体   English

useNavigate 替换选项有什么作用?

[英]What does useNavigate replace option do?

The docs say: 文档说:

Either pass a To value (same type as <Link to> ) with an optional second { replace, state } arg or使用可选的第二个{ replace, state } arg 传递To值(与<Link to>类型相同)或

without saying what it does.不用说它做了什么。 So does it replace the whole history stack or just the current route?那么它是替换整个历史堆栈还是仅替换当前路由? I have no idea.我不知道。

The replace options property is a REPLACE navigation action. replace选项属性是一个替换导航操作。 It's a redirect, replacing the current entry in the history stack versus PUSHing a new entry onto the top like a regular navigation.这是一个重定向,替换历史堆栈中的当前条目,而不是像常规导航一样将新条目推到顶部。

navigate(path); // PUSH, navigate
navigate(path, { replace: true }); // REPLACE, redirect

useNavigate使用导航

The useNavigate hook returns a function that lets you navigate programmatically, for example after a form is submitted. useNavigate钩子返回一个允许您以编程方式导航的函数,例如在提交表单之后。 If using replace: true , the navigation will replace the current entry in the history stack instead of adding a new one .如果使用replace: true导航将替换历史堆栈中的当前条目,而不是添加新条目

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM