Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip ++api++ from in-browser location changes #4834

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/middleware/blacklistRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,30 @@ const blacklistRoutes = ({ dispatch, getState }) => (next) => (action) => {

switch (action.type) {
case '@@router/LOCATION_CHANGE':
const { pathname } = action.payload.location;
let { pathname } = action.payload.location;
const { externalRoutes = [] } = config.settings;

const route = externalRoutes.find((route) =>
matchPath(pathname, route.match),
);

let actionToSend = action;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK here, in Javascript, actionToSend is a reference to action. So removing this assignment, and directly changing the action object above, has the same effect. Otherwise, if the intent was to keep the action object as is, there is a problem.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mamico I agree on the behaviour of actionToSend being a reference and so this should be redundant, however I was experiencing some issues with it using the outdated URL if I didn't take a reference to it first.

Updated PR in #4854

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(action);
return next(actionToSend);
} else {
window.location.replace(
route.url ? route.url(action.payload) : pathname,
route.url ? route.url(actionToSend.payload) : pathname,
);
}
break;
Expand Down