react-router-dom v6

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());

 

上一篇:Docker 系列一(概念原理和安装).


下一篇:go language --- techory diary 15 Dec