Skip to content

Commit 245008d

Browse files
authored
Merge pull request #51 from Shinyaigeek/fix/redirect-url-with-path-prefix
Fix: redirect target url with path-prefix
2 parents 2a62d5b + d32104f commit 245008d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/plugin/wrapPageElement.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ const withI18next = (i18n: I18n, context: I18NextContext) => (children: any) =>
1616
);
1717
};
1818

19+
const removePathPrefix = (pathname: string) => {
20+
const pathPrefix = withPrefix('/');
21+
if (pathname.startsWith(pathPrefix)) {
22+
return pathname.replace(pathPrefix, '/');
23+
}
24+
25+
return pathname;
26+
};
27+
1928
export const wrapPageElement = (
2029
{element, props}: WrapPageElementBrowserArgs<any, PageContext>,
2130
{
@@ -51,7 +60,9 @@ export const wrapPageElement = (
5160

5261
if (detected !== defaultLanguage) {
5362
const queryParams = search || '';
54-
const newUrl = withPrefix(`/${detected}${location.pathname}${queryParams}${location.hash}`);
63+
const newUrl = withPrefix(
64+
`/${detected}${removePathPrefix(location.pathname)}${queryParams}${location.hash}`
65+
);
5566
window.location.replace(newUrl);
5667
return null;
5768
}

0 commit comments

Comments
 (0)