AWS S3 Web Hosting React Routing Problem

aws s3 static website로 react 어플을 hosting하면서 아래와 같은 문제가 있었다.


 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 해주면 해결됨.


댓글

이 블로그의 인기 게시물

[Protocol] WIEGAND 통신

Orange for Oracle에서 한글 깨짐 해결책

[URL] 대소문자를 구분하나?