wuji.xwt 13989d3cc9 refactor: js to ts for rax-provider
Link: https://code.aone.alibaba-inc.com/ali-lowcode/ali-lowcode-engine/codereview/3678180

* refactor: rax-provider

* feat: add build command

* chore: compilerOptions for rax-provider
2020-09-07 13:32:26 +08:00

27 lines
647 B
TypeScript

import { useRouter } from 'rax-use-router';
import { createHashHistory, createBrowserHistory } from 'history';
const getConfig = (config) => {
let { history } = config;
const { routes } = config;
if (typeof history === 'string') {
if (history === 'hash') {
history = createHashHistory();
} else if (history === 'browser') {
history = createBrowserHistory();
}
}
return () => ({
history,
routes,
});
};
export default function getRouter(config) {
return function Router() {
const configWrapper = getConfig(config);
const { component } = useRouter(configWrapper);
return component;
};
}