[英]Redirect in react router v6?
I have defined routing in my application like我在我的应用程序中定义了路由,例如
<Route path="/settings/*" element={<AccountSettings />}>
and in one of my components I defined another route like在我的一个组件中,我定义了另一条路线,例如
<Route
path="security"
element={< Example />>
Everything is being routed correctly, in this example /settings/security However I want user to be redirected to /settings/profile whenever user hits this component?一切都被正确路由,在这个例子中 /settings/security 但是我希望用户在用户点击这个组件时被重定向到 /settings/profile?
Is there a way to default the routing to be /settings/profile?有没有办法将路由默认为/settings/profile? (I've tried useEffect but that seems very inefficient)
(我试过 useEffect 但这似乎效率很低)
<Route path="/settings/*" element={<AccountSettings />}></Route>
<Route
path="/settings"
element={<Navigate to="./profile" />}
></Route>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.