mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 18:35:09 +01:00
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
import React from 'react';
|
|
import invariant from 'invariant';
|
|
import { createRoutes } from 'react-router';
|
|
|
|
const { string, bool, func, object, oneOfType } = React.PropTypes;
|
|
|
|
const ProxyRoute = React.createClass({
|
|
propTypes: {
|
|
path: string,
|
|
ignoreScrollBehavior: bool,
|
|
handler: oneOfType([ func, string ]),
|
|
component: oneOfType([ func, string ]),
|
|
components: oneOfType([ oneOfType([ func, string ]), object ]),
|
|
getComponents: func,
|
|
proxyHandler: func
|
|
},
|
|
|
|
statics: {
|
|
createRouteFromReactElement(element) {
|
|
const createRouteFromReactElementCopy = element.type.createRouteFromReactElement;
|
|
element.type.createRouteFromReactElement = false;
|
|
const [ route ] = createRoutes(element);
|
|
element.type.createRouteFromReactElement = createRouteFromReactElementCopy;
|
|
|
|
const Component = route.component;
|
|
const ProxyHandler = element.props.proxyHandler;
|
|
route.component = ProxyHandler(Component);
|
|
|
|
return route;
|
|
}
|
|
},
|
|
|
|
render() {
|
|
invariant(
|
|
false,
|
|
'Some error message'
|
|
);
|
|
}
|
|
});
|
|
|
|
export default ProxyRoute; |