Pass props to routes
This commit is contained in:
parent
383a3f90a5
commit
216bac3bf5
2 changed files with 24 additions and 17 deletions
10
src/App.js
10
src/App.js
|
|
@ -15,12 +15,12 @@ const routes = [
|
|||
{
|
||||
title: 'Home',
|
||||
path: '/',
|
||||
component: Home,
|
||||
comp: Home,
|
||||
exact: true
|
||||
}, {
|
||||
title: 'About',
|
||||
path: '/about',
|
||||
component: About
|
||||
comp: About
|
||||
}
|
||||
]
|
||||
|
||||
|
|
@ -42,7 +42,11 @@ class App extends Component {
|
|||
</Nav>
|
||||
<Switch>
|
||||
{routes.map((route, i) => (
|
||||
<Route key={i} {...route} />
|
||||
<Route
|
||||
{...route}
|
||||
key={i}
|
||||
render={() => <route.comp {...route} />}
|
||||
/>
|
||||
))}
|
||||
<Route component={NoMatch} />
|
||||
</Switch>
|
||||
|
|
|
|||
|
|
@ -4,17 +4,20 @@ import Page from '../components/Page'
|
|||
import { Container, Section } from '../components/common'
|
||||
import PageHeader from '../components/PageHeader'
|
||||
|
||||
export default (props) => (
|
||||
<Page>
|
||||
<PageHeader title={props.title} />
|
||||
<Section thin>
|
||||
<Container>
|
||||
<h1>Welcome.</h1>
|
||||
<p>Hello!</p>
|
||||
</Container>
|
||||
</Section>
|
||||
<Helmet>
|
||||
<title>Home</title>
|
||||
</Helmet>
|
||||
</Page>
|
||||
)
|
||||
export default (props) => {
|
||||
console.log(props)
|
||||
return (
|
||||
<Page>
|
||||
<PageHeader title={props.title} />
|
||||
<Section thin>
|
||||
<Container>
|
||||
<h1>Welcome.</h1>
|
||||
<p>Hello!</p>
|
||||
</Container>
|
||||
</Section>
|
||||
<Helmet>
|
||||
<title>Home</title>
|
||||
</Helmet>
|
||||
</Page>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue