一、给路由到的组件传递props
## index.js
<Router prefix="/pms" loading={Page}>
<Route path="/(home)?" component={Page} page={Home} />
</Router>
## page.js
export default function Page(props) {
/**
*接受一个名字叫 page的props,类型是 function,他是一个模板。
*/
const { page, ...other } = props;
return (
<div key="page">
<div className="container">
// 注意这里用到了 React.createElement()方法
{page ? React.createElement(page, other) : <Loading className="inverse" />
</div>
</div>
);
}
const { func, string, shape, bool } = PropTypes;
Page.propTypes = {
page: func //page的类型是 function
};
React.createElement( type, [props], [...children])
该方法创建并返回一个给定类型的React元素。‘type’参数可以是一个String类型的标签名(如:'div'或'span'),或是一个React组件类型(一个class或者一个function)。props不必多说了。