react router V6 路由 重定向
React router V6 路由重定向
import { useRoutes, Navigate, Outlet } from "react-router-dom";
function Home() {
return <div>
<h1>父级的</h1>
<Outlet/>
</div>;
}
function One() {
console.log('11111')
return <div>One</div>;
}
function Team() {
console.log('22222')
return <div>Team</div>;
}
export default function App() {
let element = useRoutes([
{
path: "/",
element: <Home />,
children: [
{
index: true,
element: <Navigate to="/team" />,
},
{
path: "messages",
element: <One />,
},
],
},
{ path: "team", element: <Team /> },
]);
return element;
}