Skip to content
This repository has been archived by the owner on Jan 2, 2018. It is now read-only.

Commit

Permalink
Support custom basename on react-router triggered redirects and impro…
Browse files Browse the repository at this point in the history
…ve checks
  • Loading branch information
Andreas Søvik committed Dec 2, 2016
1 parent 667fce7 commit 6702d26
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ export function reactRender({
match({ history, routes: createRoutes(store), location: url },
(error, redirect, renderProps) => {
if (redirect) {
log(`Redirect request to ${redirect.pathname + redirect.search}`);
const base = redirect.basename ? redirect.basename : '';
const redirectUrl = `${base}${redirect.pathname}${redirect.search}`;
log(`Redirect request to ${redirectUrl} due to React Router`);

return resolve({
redirect: redirect.pathname + redirect.search,
redirect: redirectUrl,
});
} else if (error) {
log('Router error', pretty.render(error));
Expand Down Expand Up @@ -135,15 +138,18 @@ export function reactRender({
}
return result;
}).then(({ redialMap, redialProps }) => {
const currentUrl = `${currentLocation.pathname}${currentLocation.search}`;

if (currentUrl !== url) {
const base = currentLocation.basename ? currentLocation.basename : '';

log(`Redirect request to ${base}${currentUrl} due to history location modification`);
return resolve({
redirect: `${base}${currentUrl}`,
});
if (Object.keys(currentLocation).length > 0) {
const currentUrl = `${currentLocation.pathname}${currentLocation.search}`;

if (currentUrl !== url) {
const base = currentLocation.basename ? currentLocation.basename : '';
const redirectUrl = `${base}${currentUrl}`;

log(`Redirect request to ${redirectUrl} due to history location modification`);
return resolve({
redirect: `${redirectUrl}`,
});
}
}

let component = applyRouterMiddleware(useRedial({ redialMap }))(renderProps);
Expand Down

0 comments on commit 6702d26

Please sign in to comment.