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.
27 lines
741 B
JavaScript
27 lines
741 B
JavaScript
/* eslint-disable import/no-absolute-path */
|
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
import { ReactiveVar } from 'meteor/reactive-var';
|
|
import history from '/imports/ui/components/History/History';
|
|
|
|
export const location = new ReactiveVar(history.location.pathname);
|
|
|
|
if (Meteor.isClient) {
|
|
// history v5 hands the listener a { location, action } update object
|
|
// (v4 passed the location directly).
|
|
history.listen(({ location: loc }) => {
|
|
location.set(loc.pathname);
|
|
});
|
|
}
|
|
|
|
export const currentLocation = () => location.get();
|
|
|
|
export const currentLocationHref = () => {
|
|
if (Meteor.isClient) {
|
|
return window.location.href;
|
|
}
|
|
// FIXME
|
|
return location.get();
|
|
};
|
|
|
|
export const isHome = () => currentLocation() === '/';
|