-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNotFound.js
36 lines (29 loc) · 922 Bytes
/
NotFound.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React, { useEffect } from 'react';
import { useHistory } from 'react-router-dom';
import NotFound from '@theme-original/NotFound';
// using this as a redirection wrapper since `docusaurus/plugin-client-redirects`
// does not work with local development.
function createRedirects(url) {
// /cosmos-sdk/x-<module> -> /x-<module>
if (url.includes('/cosmos-sdk/x-')) {
return url.replace('/cosmos-sdk/x-', '/x-');
}
return url;
}
export default function NotFoundWrapper(props) {
const history = useHistory();
useEffect(() => {
const currentUrl = window.location.href;
if (currentUrl.includes('/cosmos-sdk/x-')) {
const newUrl = createRedirects(currentUrl);
window.history.replaceState({}, '', newUrl);
const relativePath = new URL(newUrl).pathname;
history.push(relativePath);
}
}, [history]);
return (
<>
<NotFound {...props} />
</>
);
}