From 764f81925be4128e25ac29f5501a80edb0bcc1e5 Mon Sep 17 00:00:00 2001 From: Brett Sun Date: Mon, 1 Feb 2016 14:48:44 +0100 Subject: [PATCH] Change `children` prop from react-router to only be a Element type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- js/components/app_base.js | 20 ++++++++++++------- js/components/ascribe_app.js | 11 ++++------ .../prize/portfolioreview/pr_app.js | 11 ++++------ .../prize/simple_prize/prize_app.js | 11 ++++------ js/components/whitelabel/wallet/wallet_app.js | 11 ++++------ js/routes.js | 10 +++++----- 6 files changed, 34 insertions(+), 40 deletions(-) diff --git a/js/components/app_base.js b/js/components/app_base.js index 044b984c..4b5d460e 100644 --- a/js/components/app_base.js +++ b/js/components/app_base.js @@ -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 (
-