USENAVIGATE替换选项做什么?

发布于 2025-02-11 07:37:46 字数 270 浏览 1 评论 0原文

docs 说:

用可选的 第二个{替换,状态} arg或

不说它做什么。那么它是否替换整个历史记录堆栈或仅仅是当前路线?我不知道。

The docs say:

Either pass a To value (same type as <Link to>) with an optional
second { replace, state } arg or

without saying what it does. So does it replace the whole history stack or just the current route? I have no idea.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

贪了杯 2025-02-18 07:37:46

替换选项属性是替换导航操作。这是一个重定向,取代了历史记录堆栈中的当前条目,而不是像常规导航那样将新条目推向顶部。

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

usenavigate

usenavigate挂钩返回一个函数,可让您导航
以编程方式,例如提交表格后。如果使用
替换:true 导航将替换当前条目
历史堆栈,而不是添加新的

The replace options property is a REPLACE navigation action. 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. If using
replace: true, the navigation will replace the current entry in the
history stack instead of adding a new one
.

神也荒唐 2025-02-18 07:37:46

您也可以使用它;

import { useLocation, Navigate } from "react-router-dom"

const location = useLocation ()

‹Navigate to="/" state={{ from: location }} replace /›

有关更多详细信息,请参见此处; https://reactrouter.com/en/main/main/hooks/hooks/use-luse-location

You can also use it like;

import { useLocation, Navigate } from "react-router-dom"

const location = useLocation ()

‹Navigate to="/" state={{ from: location }} replace /›

See here for more details; https://reactrouter.com/en/main/hooks/use-location

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文