Skip to content

Commit fa79b02

Browse files
committed
Fix GitHub Pages SPA routing by adding 404.html and updating index.html
1 parent b5c5f42 commit fa79b02

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>project2</title>
8+
<script type="text/javascript">
9+
// GitHub Pages SPA 라우팅 지원
10+
// 404.html에서 리다이렉트된 URL 파라미터를 처리
11+
(function(l) {
12+
if (l.search[1] === '/' ) {
13+
var decoded = l.search.slice(1).split('&').map(function(s) {
14+
return s.replace(/~and~/g, '&')
15+
}).join('?');
16+
window.history.replaceState(null, null,
17+
l.pathname.slice(0, -1) + decoded + l.hash
18+
);
19+
}
20+
}(window.location))
21+
</script>
822
</head>
923
<body>
1024
<div id="root"></div>

public/404.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>404</title>
6+
<script type="text/javascript">
7+
// GitHub Pages에서 SPA 라우팅을 위한 리다이렉트 스크립트
8+
// 현재 URL을 확인하고 해당 경로로 리다이렉트
9+
var pathSegmentsToKeep = 0;
10+
11+
var l = window.location;
12+
l.replace(
13+
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
14+
l.pathname.split('/').slice(0, 1 + pathSegmentsToKeep).join('/') + '/?/' +
15+
l.pathname.slice(1).split('/').slice(pathSegmentsToKeep).join('/').replace(/&/g, '~and~') +
16+
(l.search ? '&' + l.search.slice(1).replace(/&/g, '~and~') : '') +
17+
l.hash
18+
);
19+
</script>
20+
</head>
21+
<body>
22+
</body>
23+
</html>

0 commit comments

Comments
 (0)