1 | import {createSingletonHistory, MyHistoryOptions} from "@gongt/ts-stl-library/browser/history-object";
|
2 | import {GlobalVariable} from "@gongt/ts-stl-library/pattern/global-page-data";
|
3 | import * as React from "react";
|
4 | import {Router, RouterProps} from "react-router";
|
5 | import {ReactRender} from "./render";
|
6 |
|
7 | export 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 |