react router doesn't work in aws s3 bucket

前端 未结 12 1497
深忆病人
深忆病人 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:13

    I fixed it by using HashRouter instead of Router

    import { Switch, Route, HashRouter } from 'react-router-dom';
    
    const App = () => (
        
            
    );

    The app is acceccible by something like https://your-domain.s3.amazonaws.com/index.html?someParam=foo&otherPram=bar/#/projects

    on localhost like https://localhost:3000/?someParam=foo&otherPram=bar/#/projects

    No changes in S3 were needed.

提交回复
热议问题