mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 09:23:13 +01:00
Change children
prop from react-router to only be a Element type
Judging by https://github.com/rackt/react-router/blob/master/docs/API.md#children-1 and a few inspections in the code, as well as tests, the `children` prop injected into routes can only ever be a single React Element object. This allows us to easily get the active route of a child (if there is an active route) by querying the `children`’s route prop.
This commit is contained in:
parent
83012200d1
commit
764f81925b
@ -15,14 +15,10 @@ export default function AppBase(App) {
|
||||
displayName: 'AppBase',
|
||||
|
||||
propTypes: {
|
||||
children: React.PropTypes.element.isRequired,
|
||||
history: React.PropTypes.object.isRequired,
|
||||
location: React.PropTypes.object.isRequired,
|
||||
routes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired,
|
||||
|
||||
children: React.PropTypes.oneOfType([
|
||||
React.PropTypes.arrayOf(React.PropTypes.element),
|
||||
React.PropTypes.element
|
||||
])
|
||||
routes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired
|
||||
},
|
||||
|
||||
mixins: [History],
|
||||
@ -42,10 +38,20 @@ export default function AppBase(App) {
|
||||
},
|
||||
|
||||
render() {
|
||||
const { children } = this.props;
|
||||
|
||||
// Get the currently active route of the app by using the injected route parameter
|
||||
// on the currently active child route.
|
||||
// Note that despite its name, this.props.children can only ever be a single
|
||||
// React.PropTypes.element.
|
||||
const activeRoute = children.props.route;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<App {...this.props} />
|
||||
<Footer />
|
||||
<App
|
||||
{...this.props}
|
||||
activeRoute={activeRoute} />
|
||||
<GlobalNotification />
|
||||
<div id="modal" className="container" />
|
||||
</div>
|
||||
|
@ -8,16 +8,13 @@ import Header from './header';
|
||||
|
||||
let AscribeApp = React.createClass({
|
||||
propTypes: {
|
||||
routes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired,
|
||||
|
||||
children: React.PropTypes.oneOfType([
|
||||
React.PropTypes.arrayOf(React.PropTypes.element),
|
||||
React.PropTypes.element
|
||||
])
|
||||
activeRoute: React.PropTypes.object.isRequired,
|
||||
children: React.PropTypes.element.isRequired,
|
||||
routes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired
|
||||
},
|
||||
|
||||
render() {
|
||||
const { children, routes } = this.props;
|
||||
const { activeRoute, children, routes } = this.props;
|
||||
|
||||
return (
|
||||
<div className="ascribe-default-app">
|
||||
|
@ -19,13 +19,10 @@ import { getCookie } from '../../../../utils/fetch_api_utils';
|
||||
|
||||
let PRApp = React.createClass({
|
||||
propTypes: {
|
||||
activeRoute: React.PropTypes.object.isRequired,
|
||||
children: React.PropTypes.element.isRequired,
|
||||
history: React.PropTypes.object.isRequired,
|
||||
routes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired,
|
||||
|
||||
children: React.PropTypes.oneOfType([
|
||||
React.PropTypes.arrayOf(React.PropTypes.element),
|
||||
React.PropTypes.element
|
||||
])
|
||||
routes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
@ -60,7 +57,7 @@ let PRApp = React.createClass({
|
||||
|
||||
|
||||
render() {
|
||||
const { children, history, routes } = this.props;
|
||||
const { activeRoute, children, history, routes } = this.props;
|
||||
const { currentUser } = this.state;
|
||||
const subdomain = getSubdomain();
|
||||
|
||||
|
@ -13,17 +13,14 @@ import { getSubdomain } from '../../../../utils/general_utils';
|
||||
|
||||
let PrizeApp = React.createClass({
|
||||
propTypes: {
|
||||
activeRoute: React.PropTypes.object.isRequired,
|
||||
children: React.PropTypes.element.isRequired,
|
||||
history: React.PropTypes.object.isRequired,
|
||||
routes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired,
|
||||
|
||||
children: React.PropTypes.oneOfType([
|
||||
React.PropTypes.arrayOf(React.PropTypes.element),
|
||||
React.PropTypes.element
|
||||
])
|
||||
routes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired
|
||||
},
|
||||
|
||||
render() {
|
||||
const { children, history, routes } = this.props;
|
||||
const { activeRoute, children, history, routes } = this.props;
|
||||
const subdomain = getSubdomain();
|
||||
|
||||
// The second element of routes is always the active component object, where we can
|
||||
|
@ -11,17 +11,14 @@ import { getSubdomain } from '../../../utils/general_utils';
|
||||
|
||||
let WalletApp = React.createClass({
|
||||
propTypes: {
|
||||
activeRoute: React.PropTypes.object.isRequired,
|
||||
children: React.PropTypes.element.isRequired,
|
||||
history: React.PropTypes.object.isRequired,
|
||||
routes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired,
|
||||
|
||||
children: React.PropTypes.oneOfType([
|
||||
React.PropTypes.arrayOf(React.PropTypes.element),
|
||||
React.PropTypes.element
|
||||
])
|
||||
routes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired
|
||||
},
|
||||
|
||||
render() {
|
||||
const { children, history, routes } = this.props;
|
||||
const { activeRoute, children, history, routes } = this.props;
|
||||
const subdomain = getSubdomain();
|
||||
|
||||
// The second element of routes is always the active component object, where we can
|
||||
|
@ -6,7 +6,7 @@ import { Route } from 'react-router';
|
||||
import getPrizeRoutes from './components/whitelabel/prize/prize_routes';
|
||||
import getWalletRoutes from './components/whitelabel/wallet/wallet_routes';
|
||||
|
||||
import App from './components/ascribe_app';
|
||||
import AscribeApp from './components/ascribe_app';
|
||||
|
||||
import PieceList from './components/piece_list';
|
||||
import PieceContainer from './components/ascribe_detail/piece_container';
|
||||
@ -29,7 +29,7 @@ import { ProxyHandler, AuthRedirect } from './components/ascribe_routes/proxy_ha
|
||||
|
||||
|
||||
const COMMON_ROUTES = (
|
||||
<Route path='/' component={App}>
|
||||
<Route path='/' component={AscribeApp}>
|
||||
<Route
|
||||
path='login'
|
||||
component={ProxyHandler(AuthRedirect({to: '/collection', when: 'loggedIn'}))(LoginContainer)} />
|
||||
|
Loading…
Reference in New Issue
Block a user