index.tsx 686 B

1234567891011121314151617181920212223242526272829303132
  1. import { hasToken } from "@//utils/storage";
  2. import { MessageFu } from "@/utils/message";
  3. import React from "react";
  4. import { Redirect, Route } from "react-router-dom";
  5. type AtahType = {
  6. path: string;
  7. component: React.FC;
  8. [x: string]: any;
  9. };
  10. export default function AuthRoute({ path, component: Com, ...rest }: AtahType) {
  11. return (
  12. <Route
  13. path={path}
  14. {...rest}
  15. render={() => {
  16. if (hasToken()) return <Com />;
  17. else {
  18. MessageFu.warning("登录失效!");
  19. return (
  20. <Redirect
  21. to={{
  22. pathname: "/login",
  23. }}
  24. />
  25. );
  26. }
  27. }}
  28. />
  29. );
  30. }