Upgrade to react-router v5 (#25047)

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Renaud Chaput 2023-10-19 19:44:55 +02:00 committed by GitHub
parent 126cd7705d
commit 1b70d7ed7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
42 changed files with 419 additions and 361 deletions

View file

@ -1,7 +1,7 @@
import PropTypes from 'prop-types';
import { Component, PureComponent, cloneElement, Children } from 'react';
import { Component, cloneElement, Children } from 'react';
import { Switch, Route } from 'react-router-dom';
import { Switch, Route, useLocation } from 'react-router-dom';
import StackTrace from 'stacktrace-js';
@ -10,27 +10,20 @@ import ColumnLoading from '../components/column_loading';
import BundleContainer from '../containers/bundle_container';
// Small wrapper to pass multiColumn to the route components
export class WrappedSwitch extends PureComponent {
static contextTypes = {
router: PropTypes.object,
};
export const WrappedSwitch = ({ multiColumn, children }) => {
const location = useLocation();
render () {
const { multiColumn, children } = this.props;
const { location } = this.context.router.route;
const decklessLocation = multiColumn && location.pathname.startsWith('/deck')
? {...location, pathname: location.pathname.slice(5)}
: location;
const decklessLocation = multiColumn && location.pathname.startsWith('/deck')
? {...location, pathname: location.pathname.slice(5)}
: location;
return (
<Switch location={decklessLocation}>
{Children.map(children, child => child ? cloneElement(child, { multiColumn }) : null)}
</Switch>
);
};
return (
<Switch location={decklessLocation}>
{Children.map(children, child => child ? cloneElement(child, { multiColumn }) : null)}
</Switch>
);
}
}
WrappedSwitch.propTypes = {
multiColumn: PropTypes.bool,