import Home from '@/pages/home/home'; import UseGuide from "@/pages/useGuide/useGuide"; import { HashRouter, useRoutes, Navigate } from 'react-router-dom'; const Router = () => { function Routes() { const routes = useRoutes([ { path: '/', element: <Navigate to="/home" /> }, //重定向 { path: '/home', element: <Home /> }, { path: '/use-guide', element: <UseGuide /> }, ]); return routes; } return ( <HashRouter> <Routes /> </HashRouter> ) } export default Router;
使用 获取路由参数,如果不知道可以打印一下既可以
import { useParams, useSearchParams, useLocation } from "react-router-dom";
console.log(useSearchParams(),useLocation(),useParams());