File size: 1,735 Bytes
181e22f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import ReactGA from 'react-ga';
import {
withRouter,
} from 'react-router';
import {
Switch,
Route,
} from 'react-router-dom';
import * as Sentry from '@sentry/browser';
import Footer from '../components/Footer';
import HomePage from '../pages/HomePage';
import './App.css';
import './App.cm.styl';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
hasError: false,
};
}
componentDidMount() {
if (process.env.NODE_ENV === 'production') {
this.props.history.listen(location => {
ReactGA.pageview(location.pathname);
});
}
}
static getDerivedStateFromError() {
return { hasError: true };
}
componentDidCatch(error, errorInfo) {
Sentry.withScope(scope => {
Object.keys(errorInfo).forEach(key => {
scope.setExtra(key, errorInfo[key]);
});
Sentry.captureException(error);
});
}
render() {
const {
hasError,
} = this.state;
if (hasError) {
return (
<>
<h1 style={{ textAlign: 'center' }}>抱歉页面出现错误,我们的工程师已经收到通知,会尽快处理。您可以:<a href="">点此刷新页面重试</a></h1>
</>
);
}
return (
<Switch>
<Route path="/">
<HomePage />
<Footer />
</Route>
</Switch>
);
}
}
App.propTypes = {
sendHello: PropTypes.func,
user: PropTypes.object,
history: PropTypes.object,
};
function mapStateToProps(state) {
return {
user: state.user,
};
}
export default withRouter(connect(mapStateToProps, {
})(App));
|