deer / client /src /components /App.js
linuxrun's picture
Upload 120 files
181e22f verified
Raw History Blame Contribute Delete
1.74 kB
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));