Skip to content

Instantly share code, notes, and snippets.

@elisherer
Created November 21, 2024 15:15
Show Gist options
  • Save elisherer/420810ac48775e86e400258aa8a3a030 to your computer and use it in GitHub Desktop.
Save elisherer/420810ac48775e86e400258aa8a3a030 to your computer and use it in GitHub Desktop.
Fix for client routing in github pages (SPA)
<!DOCTYPE html>
<html lang="en">
<head>
<title>Website</title>
<!-- client router fix for github pages -->
<script type="text/javascript">
location.replace(`${location.origin}?client_redirect=${encodeURIComponent(location.href)}`);
</script>
<!-- client router fix for github pages -->
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Website</title>
<!-- client router fix for github pages -->
<script type="text/javascript">
const cr = new URLSearchParams(location.search).get('client_redirect');
if (cr) {
const u = new URL(cr);
history.replaceState(null, null, u.pathname + u.search + u.hash);
}
</script>
<!-- client router fix for github pages -->
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment