Skip to content

Commit

Permalink
Handle Github pages 404 issue
Browse files Browse the repository at this point in the history
Signed-off-by: Jitendra Gundaniya <[email protected]>
  • Loading branch information
jitu5 committed Nov 7, 2024
1 parent 02331cc commit 8a73355
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
23 changes: 23 additions & 0 deletions public/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- Handle GitHub Pages redirect by storing the requested path and redirecting to the root -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Redirecting</title>
<p>Redirecting...</p>
<script>
try {
const path = window.location.pathname.slice(1);
const search = window.location.search;
if (window.localStorage) {
localStorage.setItem('ghp-redirect-path', `${path}${search}`);
}
window.location.href = '../';
} catch (e) {
console.error('Failed to handle redirect:', e);
window.location.href = '/'; // Fallback to root
}
</script>
</head>
<body></body>
</html>
16 changes: 15 additions & 1 deletion src/components/flowchart-wrapper/flowchart-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ export const FlowChartWrapper = ({
matchedFocusedNode,
} = findMatchedPath(pathname, search);

useEffect(() => {
// Handle GitHub Pages redirect by checking for a stored path and navigating to it if present
let ghpRedirectPath = localStorage.getItem('ghp-redirect-path');
if (ghpRedirectPath) {
history.push(ghpRedirectPath);
}
}, []);

Check warning on line 104 in src/components/flowchart-wrapper/flowchart-wrapper.js

View workflow job for this annotation

GitHub Actions / javascript_lint_and_tests

React Hook useEffect has a missing dependency: 'history'. Either include it or remove the dependency array

Check warning on line 104 in src/components/flowchart-wrapper/flowchart-wrapper.js

View workflow job for this annotation

GitHub Actions / javascript_lint_and_tests

React Hook useEffect has a missing dependency: 'history'. Either include it or remove the dependency array

/**
* On initial load & when user switch active pipeline,
* sets the query params from local storage based on NodeType, tag, expandAllPipelines and active pipeline.
Expand Down Expand Up @@ -131,7 +139,13 @@ export const FlowChartWrapper = ({
};

useEffect(() => {
setParamsFromLocalStorage(activePipeline);
// After processing the redirect, remove the stored path or set parameters from local storage
let ghpRedirectPath = localStorage.getItem('ghp-redirect-path');
if (ghpRedirectPath) {
localStorage.removeItem('ghp-redirect-path');
} else {
setParamsFromLocalStorage(activePipeline);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [activePipeline, tag, nodeType, expandAllPipelines]);

Expand Down

0 comments on commit 8a73355

Please sign in to comment.