useLocation.tsx 512 B

12345678910111213141516171819202122
  1. import { useLocation } from 'umi';
  2. import { useEffect, useState } from 'react';
  3. import { historyStateModel } from '@/hooks/route/useHistory';
  4. const useLocations = () => {
  5. const umiLocation = useLocation();
  6. const [location, setLocation] = useState<any>({});
  7. useEffect(() => {
  8. setLocation({
  9. ...umiLocation,
  10. state: historyStateModel.state,
  11. });
  12. return () => {
  13. historyStateModel.state = undefined;
  14. };
  15. }, [umiLocation]);
  16. return location;
  17. };
  18. export default useLocations;