-
-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathgatsby-browser.js
More file actions
27 lines (26 loc) · 932 Bytes
/
gatsby-browser.js
File metadata and controls
27 lines (26 loc) · 932 Bytes
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
function checkRedirect(inPath) {
const path = inPath.replace(/\/+$/, "");
if (path === "/postgraphile" || path.startsWith("/postgraphile/")) {
const parts = path.split("/");
if (!parts[2]) {
window.location.replace(`https://postgraphile.org`);
} else {
if (parts[2] === "introduction") parts.length = 2;
parts.splice(2, 0, "4");
window.location.replace(`https://postgraphile.org${parts.join("/")}`);
}
}
if (path === "/graphile-build" || path.startsWith("/graphile-build/")) {
const parts = path.split("/");
if (!parts[2]) {
window.location.replace(`https://build.graphile.org`);
} else {
if (parts[2] === "introduction") parts.length = 2;
parts.splice(2, 0, "4");
window.location.replace(`https://build.graphile.org${parts.join("/")}`);
}
}
}
exports.onRouteUpdate = ({ location, prevLocation }) => {
checkRedirect(location.pathname);
};