File size: 825 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import React from 'react';
export interface RouterProviderProps {
route: string;
fullRoute?: string;
parent?: any;
}
const createRouter = () => {
const context = React.createContext<RouterProviderProps>({
route: '',
});
// not sure if this supposed to be unused, ignoring ts error for now
// @ts-ignore
const Router: React.SFC<RouterProviderProps> = (props) => {
const { route, fullRoute, parent, children } = props;
if (process.env.NODE_ENV !== 'production') {
if (typeof route !== 'string') {
throw new TypeError('Router route must be a string.');
}
}
return React.createElement(context.Provider as any, {
value: {
fullRoute: fullRoute || route,
route,
parent,
},
children,
});
};
};
export default createRouter;
|