import React from "react";
import { createHashRouter, RouterProvider } from "react-router-dom";
import useUserModel from "@/store/user";
import { getAllRoutes } from "./routes";
import { getAuthedRoutes } from "./permissions";

export default (props) => {
  const [user] = useUserModel();

  // 用户改变，路由改变
  const router = React.useMemo(() => {
    const authedRoutes = getAuthedRoutes();
    const allRoutes = getAllRoutes(authedRoutes);
    return createHashRouter(allRoutes || []);
  }, [user]);
  
  return <RouterProvider router={router} />
}
