其他分享
首页 > 其他分享> > react-router-dom v6

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

 

标签:dom,home,import,element,react,v6,path,router
来源: https://www.cnblogs.com/ZhiXing-Blogs/p/15793681.html