对react-router-dom6 BrowersRouter源码改动,让其暴露出history对象

62 阅读1分钟
export function MyBrowserRouter(_ref :any) {
    let {
      basename,
      children,
    } = _ref;
    let historyRef :any= useRef();


    if (historyRef.current == null) {
      historyRef.current = customHistory
    }

    let history = historyRef.current;
    let [state, setState] = useState({
      action: history.action,
      location: history.location
    });
    useLayoutEffect(() => history.listen(setState), [history]);
    return /*#__PURE__*/createElement(Router, {
      basename: basename,
      children: children,
      location: state.location,
      navigationType: state.action,
      navigator: history
    });
  }