Skip to content

Commit

Permalink
Using official recommended withRouter,fix _reactInternalInstance unde…
Browse files Browse the repository at this point in the history
…fined.
  • Loading branch information
airycanon committed Jan 8, 2018
1 parent eda40a2 commit b0acbaf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
// module.hot is disabled), so keeping it and related plugins contained
// within webpack helps prevent unexpected errors.
{
"presets": ['es2015', "react", "stage-0"],
"presets": ["es2015", "react", "stage-0"],
"plugins": ["babel-polyfill", "transform-decorators-legacy"],
"env": {
"production": {
"presets": ["react-optimize"]
},
"development": {
"presets": ["react-hmre"]
},
},
}
}
}
9 changes: 6 additions & 3 deletions src/js/pages/UserInfo/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import React, { Component } from 'react';
import {withRouter} from 'react-router-dom';
import { inject, observer } from 'mobx-react';
import pinyin from 'han';
import clazz from 'classname';
Expand Down Expand Up @@ -42,7 +43,7 @@ import helper from 'utils/helper';
},
}))
@observer
export default class UserInfo extends Component {
class UserInfo extends Component {
state = {
showEdit: false,
};
Expand Down Expand Up @@ -79,8 +80,8 @@ export default class UserInfo extends Component {
}

handleAction(user) {
if (this._reactInternalInstance._context.location.pathname !== '/') {
this._reactInternalInstance._context.router.push('/');
if (this.props.history.location.pathname !== '/') {
this.props.history.push('/');
}

setTimeout(() => {
Expand Down Expand Up @@ -231,3 +232,5 @@ export default class UserInfo extends Component {
);
}
}

export default withRouter(UserInfo);

0 comments on commit b0acbaf

Please sign in to comment.