导航“到”是否支持二级转发?
是的,它将导航到您指定的任何路径。
OTAndTOGateKeeper
是布局路线组件,因此
必须
渲染a
Outlet
嵌套路线渲染组件
element
内容进入。它也不能返回重定向到它正在包装的路线(
因为这取代了
折扣店
然后什么也没渲染!
).
OTAndTOForm
将在
/otAndTO
索引路线,因此
OTA和TOGateKeeper
也不应该试图渲染它。
更新
OTA和TOGateKeeper
具体如下:
import { Navigate, Outlet } from 'react-router-dom';
import OTAndTOForm from "./OTAndTOForm.jsx";
export default function OTAndTOGateKeeper() {
return sessionStorage.getItem("accessToken")
? <Outlet />
: <Navigate to="/otAndTO/login" replace />;
}
重新排列路线,以便
OTAndTOForm
索引路线和
LoginForm
登录路由在父级下呈现
"/otAndTO"
路线和渲染
OTA和TOGateKeeper
作为仅在周围受保护的布局路线
OTAndTOForm
路线。
<Router>
<Routes>
<Route path="/otAndTO">
<Route element={<OTAndTOGateKeeper />}>
<Route index element={<OTAndTOForm />} /> {/* "/otAndTO" */}
</Route>
<Route path="login" element={<LoginForm />} /> {/* "/otAndTO/login" */}
</Route>
</Routes>
</Router>