| 1023 | }; |
| 1024 | |
| 1025 | const About = () => <div>About</div>; |
| 1026 | |
| 1027 | // Mimics https://github.com/ReactTraining/react-router/blob/master/packages/react-router/modules/Router.js |
| 1028 | function Router({children}) { |
| 1029 | const [path, setPath] = React.useState('/'); |
| 1030 | return ( |
| 1031 | <RouterContext.Provider value={{path, setPath}}> |
| 1032 | {children} |
| 1033 | </RouterContext.Provider> |
| 1034 | ); |
| 1035 | } |
| 1036 | |
| 1037 | // Mimics https://github.com/ReactTraining/react-router/blob/master/packages/react-router/modules/Switch.js |
| 1038 | function Switch({children}) { |
| 1039 | return ( |
| 1040 | <RouterContext.Consumer> |
| 1041 | {context => { |
| 1042 | let element = null; |
| 1043 | React.Children.forEach(children, child => { |
| 1044 | if (context.path === child.props.path) { |
| 1045 | element = child.props.children; |
| 1046 | } |
| 1047 | }); |
| 1048 | return element ? React.cloneElement(element) : null; |
| 1049 | }} |
| 1050 | </RouterContext.Consumer> |
| 1051 | ); |
| 1052 | } |
| 1053 | |
| 1054 | // Mimics https://github.com/ReactTraining/react-router/blob/master/packages/react-router/modules/Route.js |
| 1055 | function Route({children, path}) { |