deps: react-router-dom 4 -> 6 (history 5, react-router-bootstrap 0.26)
Removes the Router/Switch/Route/Link/LinkContainer legacy-context
warnings. Keeps the shared history singleton (used outside React by
NotificationsObserver + Utils/location) via unstable_HistoryRouter, and
bridges v6 hooks back to v4-shaped history/match/location props with a
new withRouterCompat HOC so the ~20 class pages stay untouched.
- <Switch> -> <Routes>, component= -> element=
- Authenticated/Public -> guard components (children or <Navigate replace>)
- LocationListener -> useLocation + useEffect function
- regex route /fire/:type(active|archive|alert)/:id -> /fire/:type/:id
- history.listen callback is ({ location }) in history v5
Browser-verified: SPA nav, /subscriptions->/login auth redirect,
deep-link /fire/archive/:id (params), browser back/forward. REST smoke
byte-identical.
This commit is contained in:
parent
a1a1b9a801
commit
e2d13ca64c
10 changed files with 177 additions and 212 deletions
|
|
@ -1,27 +1,20 @@
|
|||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Route, Redirect } from 'react-router-dom';
|
||||
import { Navigate, useLocation } from 'react-router-dom';
|
||||
|
||||
const Public = ({
|
||||
loggingIn, authenticated, component, location, path, exact, ...rest
|
||||
}) => (
|
||||
<Route
|
||||
path={path}
|
||||
exact={exact}
|
||||
render={props => (
|
||||
!authenticated ?
|
||||
(React.createElement(component, {
|
||||
...props, ...rest, loggingIn, authenticated
|
||||
})) :
|
||||
(<Redirect to={{ pathname: '/subscriptions', state: location.state }} />)
|
||||
)}
|
||||
/>
|
||||
);
|
||||
// v6 route guard for public-only pages (login/signup/auth): rendered as a route
|
||||
// `element` wrapping the real page. Redirects authenticated users to their
|
||||
// subscriptions, preserving any location state (e.g. a pending new-zone flow).
|
||||
const Public = ({ authenticated, children }) => {
|
||||
const location = useLocation();
|
||||
return authenticated
|
||||
? <Navigate to="/subscriptions" state={location.state} replace />
|
||||
: children;
|
||||
};
|
||||
|
||||
Public.propTypes = {
|
||||
loggingIn: PropTypes.bool.isRequired,
|
||||
authenticated: PropTypes.bool.isRequired,
|
||||
component: PropTypes.elementType.isRequired
|
||||
children: PropTypes.node.isRequired
|
||||
};
|
||||
|
||||
export default Public;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue