[Glitch] Upgrade to react-router v5

Port 1b70d7ed7c to glitch-soc

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Renaud Chaput
2023-10-19 19:44:55 +02:00
committed by Claire
parent 245513d630
commit d6eacb79c6
51 changed files with 413 additions and 385 deletions

View File

@@ -1,25 +1,27 @@
import PropTypes from 'prop-types';
import { PureComponent } from 'react';
import { FormattedMessage } from 'react-intl';
import { withRouter } from 'react-router-dom';
import { Icon } from 'flavours/glitch/components/icon';
import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router';
export default class ColumnBackButtonSlim extends PureComponent {
class ColumnBackButtonSlim extends PureComponent {
static contextTypes = {
router: PropTypes.object,
static propTypes = {
...WithRouterPropTypes,
};
handleClick = () => {
const { router } = this.context;
const { location, history } = this.props;
// Check if there is a previous page in the app to go back to per https://stackoverflow.com/a/70532858/9703201
// When upgrading to V6, check `location.key !== 'default'` instead per https://github.com/remix-run/history/blob/main/docs/api-reference.md#location
if (router.route.location.key) {
router.history.goBack();
if (location.key) {
history.goBack();
} else {
router.history.push('/');
history.push('/');
}
};
@@ -35,3 +37,5 @@ export default class ColumnBackButtonSlim extends PureComponent {
}
}
export default withRouter(ColumnBackButtonSlim);