• Home
  • About
    • lahuman photo

      lahuman

      열심히 사는 아저씨

    • Learn More
    • Facebook
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

Vuejs를 express로 배포 후 vuejs route 동작 처리

30 Jan 2019

Reading time ~1 minute

Vuejs 배포시 route 동작 처리

vuejs에서 express로 배포하는 방식을 기존에 설명 했었다.

문제는 vuejs route에 주소를 직접 치고 들어가면 404 오류가 발생하였다.

express쪽에서 기본적인 요청은 vuejs의 route를 바라보게 하고 싶어서 검색을 해보니, Routes not working in production라는 글을 확인 하였다.

처리 방법은 express에 마지막 부분에 다음 코드를 추가 하면 된다. index.html은 vuejs를 배포한 위치이다.

app.get('*', (req, res) => {
  res.sendFile(`${__dirname}/public/index.html`);
});

vuejs도 잼나네!

참고 자료

  • Routes not working in production
  • HTML5 History Mode


vue Share Tweet +1