호스팅별 해결 방법
Cloudflare Cloudflare Pages
프로젝트 루트 또는 public 폴더에 _redirects 파일을 생성하세요.
public/_redirects
/* /index.html 200Vercel
vercel.json
{
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" }
]
}Netlify
public/_redirects
/* /index.html 200
또는 netlify.toml 파일:
netlify.toml
[[redirects]]
from = "/*"
to = "/index.html"
status = 200Nginx
nginx.conf
server {
listen 80;
server_name your-domain.com;
root /var/www/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}왜 이런 문제가 발생하나요?
SPA는 JavaScript가 브라우저에서 URL을 처리합니다. 하지만 새로고침하면 브라우저가 서버에 해당 경로를 요청하고, 서버는 그 경로에 실제 파일이 없으니 404를 반환합니다. 해결책은 모든 요청을 index.html로 보내서 JS가 라우팅을 처리하게 하는 것입니다.