[英]create multiple pages react router using json in react
How to create multiple pages where header and footer will be static and inside content image , text etc will fetched from .json file in using react and react router 如何创建多个页面,其中页眉和页脚将是静态的,并且在使用react和react router时将从.json文件中提取内容图像,文本等
i have already something like this 我已经有这样的东西
import React, { PropTypes } from 'react';
import withStyles from 'isomorphic-style-loader/lib/withStyles';
import s from './Contact.css';
const title = 'Contact Us';
function Contact(props, context) {
context.setTitle(title);
return (
<div className={s.root}>
<div className={s.container}>
<h1>{title}</h1>
<p>...</p>
</div>
</div>
);
}
Contact.contextTypes = { setTitle: PropTypes.func.isRequired };
export default withStyles(s)(Contact);
i want that .json file content will replace value inside {} 我希望.json文件内容将替换{}中的值
The link below provides a good example of nested navigation. 下面的链接提供了嵌套导航的一个很好的示例。
https://github.com/ReactTraining/react-router/blob/master/docs/guides/RouteConfiguration.md https://github.com/ReactTraining/react-router/blob/master/docs/guides/RouteConfiguration.md
If you look at the routing configuration in this example, you will see that the rendered components are nested. 如果在此示例中查看路由配置,则会看到呈现的组件是嵌套的。
render((
<Router>
<Route path="/" component={App}>
<Route path="about" component={About} />
<Route path="inbox" component={Inbox}>
<Route path="messages/:id" component={Message} />
</Route>
</Route>
</Router>
), document.body)
The about
and inbox
routes will ensure that the component is passed to the root component ( /
) as props.children
, which can be used like this: about
和inbox
路由将确保该组件作为props.children
传递到根组件( /
),可以这样使用:
const App = React.createClass({
render() {
return (
<div>
<h1>App</h1>
<ul>
<li><Link to="/about">About</Link></li>
<li><Link to="/inbox">Inbox</Link></li>
</ul>
{this.props.children}
</div>
)
}
})
In this example you can see the App
component as your root component that will always be rendered, so this would be the most fitting place for a header and footer. 在此示例中,您可以将
App
组件视为始终将被呈现的根组件,因此这将是最适合页眉和页脚的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.