forked from italia/design-comuni-plone-theme
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: backport blacklistRoutes (#305)
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* backport https://github.com/plone/volto/pull/4854 | ||
*/ | ||
|
||
import config from '@plone/volto/registry'; | ||
import { matchPath } from 'react-router'; | ||
|
||
const blacklistRoutes = ({ dispatch, getState }) => (next) => (action) => { | ||
if (typeof action === 'function') { | ||
return next(action); | ||
} | ||
|
||
switch (action.type) { | ||
case '@@router/LOCATION_CHANGE': | ||
debugger; | ||
let { pathname } = action.payload.location; | ||
const { externalRoutes = [] } = config.settings; | ||
|
||
const route = externalRoutes.find((route) => | ||
matchPath(pathname, route.match), | ||
); | ||
|
||
let actionToSend = action; | ||
if (pathname.startsWith('/++api++')) { | ||
actionToSend.payload.location.pathname = actionToSend.payload.location.pathname.substring( | ||
8, | ||
); | ||
// To handle the `window.location.replace` | ||
pathname = actionToSend.payload.location.pathname; | ||
if (window.history) { | ||
window.history.replaceState(window.history.state, '', pathname); | ||
} | ||
} | ||
|
||
if (!route) { | ||
return next(actionToSend); | ||
} else { | ||
window.location.replace( | ||
route.url ? route.url(actionToSend.payload) : pathname, | ||
); | ||
} | ||
break; | ||
default: | ||
return next(action); | ||
} | ||
}; | ||
|
||
export default blacklistRoutes; |