Skip to content

Commit

Permalink
feat(app, experimental): 增加 RouterStore 组件,用于在外部获取 react-router 的值
Browse files Browse the repository at this point in the history
  • Loading branch information
twinh committed Apr 21, 2024
1 parent 7cb1e46 commit f4cf6a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { extendTheme, ThemeProvider } from '@chakra-ui/react';
import { ConfigProvider } from '@mxjs/config';
import useAsyncEffect from 'use-async-effect';
import ErrorBoundary from './ErrorBoundary';
import RouterStore from './RouterStore';

const importPage = async (page) => {
return page ? page.import() : NotFound;
Expand Down Expand Up @@ -95,6 +96,7 @@ const App = (
<ConfigProvider config={config}>
<ThemeProvider theme={theme}>
<Router history={history}>
<RouterStore/>
<ModalSwitch>
<Route component={loadableComponent}/>
</ModalSwitch>
Expand Down
14 changes: 14 additions & 0 deletions components/RouterStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useHistory } from 'react-router';

let history;

/**
* @experimental
*/
const RouterStore = () => {
history = useHistory();
};

export default RouterStore;

export { history };

0 comments on commit f4cf6a7

Please sign in to comment.