AWS S3 Web Hosting React Routing Problem
aws s3 static website로 react 어플을 hosting하면서 아래와 같은 문제가 있었다.
1) http://www.example.com 으로 index page는 잘 호출됨.
2) index page에서 router로 /projects나 /about은 routing이 됨.
3) 그러나, 브라우져에 url로 http://www.example.com/projects나 /about을 호출해 보면 404 Not Found 에러가 발생함.
해결방법)
아래 그림과 같이 error를 index page로 redirection 해주면 해결됨.
1 2 3 4 5 6 7 8 9 10 11 12 | const App = () => (
<Router>
<div>
<NavBar/>
<Switch>
<Route exact path="/" component={Home}/>
<Route exact path="/projects" component={Projects}/>
<Route exact path="/about" component={About}/>
</Switch>
</div>
</Router>
);
|
1) http://www.example.com 으로 index page는 잘 호출됨.
2) index page에서 router로 /projects나 /about은 routing이 됨.
3) 그러나, 브라우져에 url로 http://www.example.com/projects나 /about을 호출해 보면 404 Not Found 에러가 발생함.
해결방법)
아래 그림과 같이 error를 index page로 redirection 해주면 해결됨.

댓글
댓글 쓰기