UNPKG

766 BTypeScriptView Raw
1import {createSingletonHistory, MyHistoryOptions} from "@gongt/ts-stl-library/browser/history-object";
2import {GlobalVariable} from "@gongt/ts-stl-library/pattern/global-page-data";
3import * as React from "react";
4import {Router, RouterProps} from "react-router";
5import {ReactRender} from "./render";
6
7export function reactUseRouter(react: ReactRender, options: MyHistoryOptions = {}) {
8 const preventDuplicate = new GlobalVariable(react);
9 if (preventDuplicate.has('router')) {
10 throw new TypeError('reactUseRouter(): duplicate call to one react instance.')
11 }
12 preventDuplicate.set('router', options);
13
14 react.wrapComponent<RouterProps>('Router', Router, (global: GlobalVariable) => {
15 return {
16 history: createSingletonHistory(global, options),
17 };
18 });
19}
20
\No newline at end of file