react router doesn't work in aws s3 bucket

前端 未结 12 1510
深忆病人
深忆病人 2020-11-28 08:08

I deployed my React website build/ folder into an AWS S3 bucket.

If I go to www.mywebsite.com, it works and if I click on a ta

12条回答
  •  生来不讨喜
    2020-11-28 08:30

    I'm using NextJS and had the same issue. My solution was to check the routing information and push if it doesn't fit.

    const router = useRouter();
    useEffect(() => {
        if (!router.pathname.startsWith(router.asPath)) {
          router.push(router.asPath);
        }
      });
    

    Nothing needed to be modified at the S3 side except from routing the error page to index.html

提交回复
热议问题