From c7b46dc59107ab60906ad622f31cd8cbb1d0f9a5 Mon Sep 17 00:00:00 2001 From: bc022699 Date: Mon, 13 Feb 2017 11:47:20 -0500 Subject: [PATCH] Fix issue with props passed in via router --- .../components/pages/DynamicRoutePage.tsx | 63 +++++++++++-------- .../CreateReactElements.ts | 23 ++++--- 2 files changed, 47 insertions(+), 39 deletions(-) diff --git a/kitchen-sink/components/pages/DynamicRoutePage.tsx b/kitchen-sink/components/pages/DynamicRoutePage.tsx index ed26c63..d98f832 100644 --- a/kitchen-sink/components/pages/DynamicRoutePage.tsx +++ b/kitchen-sink/components/pages/DynamicRoutePage.tsx @@ -1,12 +1,12 @@ import * as React from 'react'; -import {Page, Navbar, ContentBlockTitle, List, ListItem, ListLabel, ListGroup, ListButton} from 'framework7-react'; +import {Page, Navbar, ContentBlockTitle, ContentBlock, List, ListItem, ListLabel, ListGroup, ListButton} from 'framework7-react'; import {getCurrentRoute} from '../App'; export class DynamicRoutePage extends React.Component { private currentRoute: any; - constructor() { - super(); + constructor(props: any, context: any) { + super(props, context); this.currentRoute = getCurrentRoute(); } @@ -16,30 +16,39 @@ export class DynamicRoutePage extends React.Component { -
    -
  • Url: {this.currentRoute.url}
  • -
  • Path: {this.currentRoute.path}
  • -
  • Hash: {this.currentRoute.hash}
  • -
  • Params: -
      - { - Object.keys(this.currentRoute.params).map((paramName, index) => { - return (
    • {`${paramName}:`} {this.currentRoute.params[paramName]}
    • ); - }) - } -
    -
  • -
  • Query: -
      - { - Object.keys(this.currentRoute.query).map((queryItem, index) => { - return (
    • {`${queryItem}:`} {this.currentRoute.query[queryItem]}
    • ); - }) - } -
    -
  • -
  • Route: {this.currentRoute.route}
  • -
+ +
    +
  • Url: {this.currentRoute.url}
  • +
  • Path: {this.currentRoute.path}
  • +
  • Hash: {this.currentRoute.hash}
  • +
  • Params: +
      + { + Object.keys(this.currentRoute.params).map((paramName, index) => { + return (
    • {`${paramName}: `}{this.currentRoute.params[paramName]}
    • ); + }) + } +
    +
  • +
  • Query: +
      + { + Object.keys(this.currentRoute.query).map((queryItem, index) => { + return (
    • {`${queryItem}:`} {this.currentRoute.query[queryItem]}
    • ); + }) + } +
    +
  • +
  • Route: {this.currentRoute.route.path}
  • +
+
+ +

Route params are also passed as component props:

+
    +
  • id: {this.props.id}
  • +
  • post_id: {this.props.post_id}
  • +
+
); } diff --git a/src/utils/reactify-vue/react-element-creation/CreateReactElements.ts b/src/utils/reactify-vue/react-element-creation/CreateReactElements.ts index db4d326..c0b91e6 100644 --- a/src/utils/reactify-vue/react-element-creation/CreateReactElements.ts +++ b/src/utils/reactify-vue/react-element-creation/CreateReactElements.ts @@ -58,20 +58,19 @@ export const createReactElement = ( if (!componentOrComponentName) return null; - if (args.tag === 'component') { - reactElement = React.createElement(componentOrComponentName as React.ComponentClass); - } else { - let resolvedComponent; - - resolvedComponent = resolveDependencyComponent(instantiatedComponents, componentOrComponentName as string); - children = flattenNestedArrayOfChildren(children); + let resolvedComponent; - if (!resolvedComponent) resolvedComponent = componentOrComponentName as React.ComponentClass | React.StatelessComponent; + if (args.tag !== 'component') { + resolvedComponent = resolveDependencyComponent(instantiatedComponents, componentOrComponentName as string); + } + + children = flattenNestedArrayOfChildren(children); - const props = propsProcessor.getProps(args, children, componentOrComponentName, resolvedComponent, vueComponent); - - reactElement = React.createElement(resolvedComponent, props); - } + if (!resolvedComponent) resolvedComponent = componentOrComponentName as React.ComponentClass | React.StatelessComponent; + + const props = propsProcessor.getProps(args, children, componentOrComponentName, resolvedComponent, vueComponent); + + reactElement = React.createElement(resolvedComponent, props); return reactElement; }; \ No newline at end of file