Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于本项目中context的使用(context.router) #4

Open
ckinmind opened this issue Feb 11, 2017 · 1 comment
Open

关于本项目中context的使用(context.router) #4

ckinmind opened this issue Feb 11, 2017 · 1 comment

Comments

@ckinmind
Copy link
Owner

在本项目中看到好多地方都定义了contextTypes, 这是在子组件里定义的,方便直接从祖先组件中获取需要的数据,然后再祖先组件中定义getChildContext,但是我怎么找也找不到哪里有定义getChildContext方法的地方,后来想到了这个应该是在Router组件定义的,因为所有组件都是Routet的子组件,一个使用案例如下

class Main extends Component {
constructor(props) {
        super(props);
        this.signout = () => {
            this.props.signin();
            this.context.router.replace({ pathname: '/' });
        }
    }
}
Main.contextTypes = {
    router: React.PropTypes.object.isRequired
};
@ckinmind
Copy link
Owner Author

context.router是跳转的一种方式,可以查看issue #5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant