Skip to content
This repository was archived by the owner on Mar 11, 2021. It is now read-only.

Commit c7b46dc

Browse files
bc022699bc022699
authored andcommitted
Fix issue with props passed in via router
1 parent 73346f7 commit c7b46dc

2 files changed

Lines changed: 47 additions & 39 deletions

File tree

kitchen-sink/components/pages/DynamicRoutePage.tsx

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import * as React from 'react';
2-
import {Page, Navbar, ContentBlockTitle, List, ListItem, ListLabel, ListGroup, ListButton} from 'framework7-react';
2+
import {Page, Navbar, ContentBlockTitle, ContentBlock, List, ListItem, ListLabel, ListGroup, ListButton} from 'framework7-react';
33
import {getCurrentRoute} from '../App';
44

55
export class DynamicRoutePage extends React.Component<any, any> {
66
private currentRoute: any;
77

8-
constructor() {
9-
super();
8+
constructor(props: any, context: any) {
9+
super(props, context);
1010

1111
this.currentRoute = getCurrentRoute();
1212
}
@@ -16,30 +16,39 @@ export class DynamicRoutePage extends React.Component<any, any> {
1616
<Page>
1717
<Navbar backLink="Back" title="Lists" sliding></Navbar>
1818

19-
<ul>
20-
<li><b>Url:</b> {this.currentRoute.url}</li>
21-
<li><b>Path:</b> {this.currentRoute.path}</li>
22-
<li><b>Hash:</b> {this.currentRoute.hash}</li>
23-
<li><b>Params:</b>
24-
<ul>
25-
{
26-
Object.keys(this.currentRoute.params).map((paramName, index) => {
27-
return (<li key={index}><b>{`${paramName}:`}</b> {this.currentRoute.params[paramName]}</li>);
28-
})
29-
}
30-
</ul>
31-
</li>
32-
<li><b>Query:</b>
33-
<ul>
34-
{
35-
Object.keys(this.currentRoute.query).map((queryItem, index) => {
36-
return (<li key={index}><b>{`${queryItem}:`}</b> {this.currentRoute.query[queryItem]}</li>);
37-
})
38-
}
39-
</ul>
40-
</li>
41-
<li><b>Route:</b> {this.currentRoute.route}</li>
42-
</ul>
19+
<ContentBlock inner>
20+
<ul>
21+
<li><b>Url:</b> {this.currentRoute.url}</li>
22+
<li><b>Path:</b> {this.currentRoute.path}</li>
23+
<li><b>Hash:</b> {this.currentRoute.hash}</li>
24+
<li><b>Params:</b>
25+
<ul>
26+
{
27+
Object.keys(this.currentRoute.params).map((paramName, index) => {
28+
return (<li key={index}><b>{`${paramName}: `}</b>{this.currentRoute.params[paramName]}</li>);
29+
})
30+
}
31+
</ul>
32+
</li>
33+
<li><b>Query:</b>
34+
<ul>
35+
{
36+
Object.keys(this.currentRoute.query).map((queryItem, index) => {
37+
return (<li key={index}><b>{`${queryItem}:`}</b> {this.currentRoute.query[queryItem]}</li>);
38+
})
39+
}
40+
</ul>
41+
</li>
42+
<li><b>Route:</b> {this.currentRoute.route.path}</li>
43+
</ul>
44+
</ContentBlock>
45+
<ContentBlock inner>
46+
<p>Route <b>params</b> are also passed as component props:</p>
47+
<ul>
48+
<li><b>id:</b> {this.props.id}</li>
49+
<li><b>post_id:</b> {this.props.post_id}</li>
50+
</ul>
51+
</ContentBlock>
4352
</Page>
4453
);
4554
}

src/utils/reactify-vue/react-element-creation/CreateReactElements.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,19 @@ export const createReactElement = (
5858

5959
if (!componentOrComponentName) return null;
6060

61-
if (args.tag === 'component') {
62-
reactElement = React.createElement(componentOrComponentName as React.ComponentClass<any>);
63-
} else {
64-
let resolvedComponent;
65-
66-
resolvedComponent = resolveDependencyComponent(instantiatedComponents, componentOrComponentName as string);
67-
children = flattenNestedArrayOfChildren(children);
61+
let resolvedComponent;
6862

69-
if (!resolvedComponent) resolvedComponent = componentOrComponentName as React.ComponentClass<any> | React.StatelessComponent<any>;
63+
if (args.tag !== 'component') {
64+
resolvedComponent = resolveDependencyComponent(instantiatedComponents, componentOrComponentName as string);
65+
}
66+
67+
children = flattenNestedArrayOfChildren(children);
7068

71-
const props = propsProcessor.getProps(args, children, componentOrComponentName, resolvedComponent, vueComponent);
72-
73-
reactElement = React.createElement(resolvedComponent, props);
74-
}
69+
if (!resolvedComponent) resolvedComponent = componentOrComponentName as React.ComponentClass<any> | React.StatelessComponent<any>;
70+
71+
const props = propsProcessor.getProps(args, children, componentOrComponentName, resolvedComponent, vueComponent);
72+
73+
reactElement = React.createElement(resolvedComponent, props);
7574

7675
return reactElement;
7776
};

0 commit comments

Comments
 (0)