mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 17:33:14 +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',
|
displayName: 'AppBase',
|
||||||
|
|
||||||
propTypes: {
|
propTypes: {
|
||||||
|
children: React.PropTypes.element.isRequired,
|
||||||
history: React.PropTypes.object.isRequired,
|
history: React.PropTypes.object.isRequired,
|
||||||
location: React.PropTypes.object.isRequired,
|
location: React.PropTypes.object.isRequired,
|
||||||
routes: React.PropTypes.arrayOf(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
|
|
||||||
])
|
|
||||||
},
|
},
|
||||||
|
|
||||||
mixins: [History],
|
mixins: [History],
|
||||||
@ -42,10 +38,20 @@ export default function AppBase(App) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
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 (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<App {...this.props} />
|
|
||||||
<Footer />
|
<Footer />
|
||||||
|
<App
|
||||||
|
{...this.props}
|
||||||
|
activeRoute={activeRoute} />
|
||||||
<GlobalNotification />
|
<GlobalNotification />
|
||||||
<div id="modal" className="container" />
|
<div id="modal" className="container" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -8,16 +8,13 @@ import Header from './header';
|
|||||||
|
|
||||||
let AscribeApp = React.createClass({
|
let AscribeApp = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
routes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired,
|
activeRoute: React.PropTypes.object.isRequired,
|
||||||
|
children: React.PropTypes.element.isRequired,
|
||||||
children: React.PropTypes.oneOfType([
|
routes: React.PropTypes.arrayOf(React.PropTypes.object).isRequired
|
||||||
React.PropTypes.arrayOf(React.PropTypes.element),
|
|
||||||
React.PropTypes.element
|
|
||||||
])
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { children, routes } = this.props;
|
const { activeRoute, children, routes } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="ascribe-default-app">
|
<div className="ascribe-default-app">
|
||||||
|
@ -19,13 +19,10 @@ import { getCookie } from '../../../../utils/fetch_api_utils';
|
|||||||
|
|
||||||
let PRApp = React.createClass({
|
let PRApp = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
|
activeRoute: React.PropTypes.object.isRequired,
|
||||||
|
children: React.PropTypes.element.isRequired,
|
||||||
history: React.PropTypes.object.isRequired,
|
history: React.PropTypes.object.isRequired,
|
||||||
routes: React.PropTypes.arrayOf(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
|
|
||||||
])
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
@ -60,7 +57,7 @@ let PRApp = React.createClass({
|
|||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { children, history, routes } = this.props;
|
const { activeRoute, children, history, routes } = this.props;
|
||||||
const { currentUser } = this.state;
|
const { currentUser } = this.state;
|
||||||
const subdomain = getSubdomain();
|
const subdomain = getSubdomain();
|
||||||
|
|
||||||
|
@ -13,17 +13,14 @@ import { getSubdomain } from '../../../../utils/general_utils';
|
|||||||
|
|
||||||
let PrizeApp = React.createClass({
|
let PrizeApp = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
|
activeRoute: React.PropTypes.object.isRequired,
|
||||||
|
children: React.PropTypes.element.isRequired,
|
||||||
history: React.PropTypes.object.isRequired,
|
history: React.PropTypes.object.isRequired,
|
||||||
routes: React.PropTypes.arrayOf(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
|
|
||||||
])
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { children, history, routes } = this.props;
|
const { activeRoute, children, history, routes } = this.props;
|
||||||
const subdomain = getSubdomain();
|
const subdomain = getSubdomain();
|
||||||
|
|
||||||
// The second element of routes is always the active component object, where we can
|
// 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({
|
let WalletApp = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
|
activeRoute: React.PropTypes.object.isRequired,
|
||||||
|
children: React.PropTypes.element.isRequired,
|
||||||
history: React.PropTypes.object.isRequired,
|
history: React.PropTypes.object.isRequired,
|
||||||
routes: React.PropTypes.arrayOf(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
|
|
||||||
])
|
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { children, history, routes } = this.props;
|
const { activeRoute, children, history, routes } = this.props;
|
||||||
const subdomain = getSubdomain();
|
const subdomain = getSubdomain();
|
||||||
|
|
||||||
// The second element of routes is always the active component object, where we can
|
// 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 getPrizeRoutes from './components/whitelabel/prize/prize_routes';
|
||||||
import getWalletRoutes from './components/whitelabel/wallet/wallet_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 PieceList from './components/piece_list';
|
||||||
import PieceContainer from './components/ascribe_detail/piece_container';
|
import PieceContainer from './components/ascribe_detail/piece_container';
|
||||||
@ -29,7 +29,7 @@ import { ProxyHandler, AuthRedirect } from './components/ascribe_routes/proxy_ha
|
|||||||
|
|
||||||
|
|
||||||
const COMMON_ROUTES = (
|
const COMMON_ROUTES = (
|
||||||
<Route path='/' component={App}>
|
<Route path='/' component={AscribeApp}>
|
||||||
<Route
|
<Route
|
||||||
path='login'
|
path='login'
|
||||||
component={ProxyHandler(AuthRedirect({to: '/collection', when: 'loggedIn'}))(LoginContainer)} />
|
component={ProxyHandler(AuthRedirect({to: '/collection', when: 'loggedIn'}))(LoginContainer)} />
|
||||||
|
Loading…
Reference in New Issue
Block a user