Commit bf73643b authored by jim's avatar jim Committed by ι™ˆεΈ…

change to new context api

parent 072e30b2
import React, { PureComponent, createElement } from 'react';
import PropTypes from 'prop-types';
import pathToRegexp from 'path-to-regexp';
import { Breadcrumb, Tabs } from 'antd';
import classNames from 'classnames';
......@@ -20,12 +19,6 @@ export function getBreadcrumb(breadcrumbNameMap, url) {
}
export default class PageHeader extends PureComponent {
static contextTypes = {
routes: PropTypes.array,
params: PropTypes.object,
location: PropTypes.object,
breadcrumbNameMap: PropTypes.object,
};
onChange = key => {
if (this.props.onTabChange) {
this.props.onTabChange(key);
......@@ -33,10 +26,10 @@ export default class PageHeader extends PureComponent {
};
getBreadcrumbProps = () => {
return {
routes: this.props.routes || this.context.routes,
params: this.props.params || this.context.params,
routerLocation: this.props.location || this.context.location,
breadcrumbNameMap: this.props.breadcrumbNameMap || this.context.breadcrumbNameMap,
routes: this.props.routes,
params: this.props.params,
routerLocation: this.props.location,
breadcrumbNameMap: this.props.breadcrumbNameMap,
};
};
// Generated according to props
......
import React from 'react';
import PropTypes from 'prop-types';
import { Layout } from 'antd';
import DocumentTitle from 'react-document-title';
import { connect } from 'dva';
......@@ -14,6 +13,7 @@ import Sidebar from '../components/Sidebar';
import logo from '../assets/logo.svg';
import Footer from './Footer';
import Header from './Header';
import Context from './MeunContext';
const { Content } = Layout;
const { AuthorizedRoute, check } = Authorized;
......@@ -61,11 +61,7 @@ const query = {
};
class BasicLayout extends React.PureComponent {
static childContextTypes = {
location: PropTypes.object,
breadcrumbNameMap: PropTypes.object,
};
getChildContext() {
getContext() {
const { location, routerData, menuData } = this.props;
return {
location,
......@@ -165,10 +161,12 @@ class BasicLayout extends React.PureComponent {
<DocumentTitle title={this.getPageTitle()}>
<ContainerQuery query={query}>
{params => (
<div className={classNames(params)}>
{layout}
<RightSidebar onChange={this.changeSetting} />
</div>
<Context.Provider value={this.getContext()}>
<div className={classNames(params)}>
{layout}
<RightSidebar onChange={this.changeSetting} />
</div>
</Context.Provider>
)}
</ContainerQuery>
</DocumentTitle>
......
import { createContext } from 'react';
export default createContext();
......@@ -3,11 +3,16 @@ import { Link } from 'dva/router';
import PageHeader from '../components/PageHeader';
import GridContent from './GridContent';
import styles from './PageHeaderLayout.less';
import MeunContext from './MeunContext';
export default ({ children, wrapperClassName, top, ...restProps }) => (
<div style={{ margin: '-24px -24px 0' }} className={wrapperClassName}>
{top}
<PageHeader key="pageheader" {...restProps} linkElement={Link} />
<MeunContext.Consumer>
{value => {
return <PageHeader {...value} key="pageheader" {...restProps} linkElement={Link} />;
}}
</MeunContext.Consumer>
{children ? (
<div className={styles.content}>
<GridContent>{children}</GridContent>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment