0

I deployed my website by copying the files in my build folder to AWS EC2's file hosting server.

Everything works fine if I start to browse the website starting from my homepage (www.website.com), but if I directly paste a url like www.website.com/createpost then it will get the 404 error.

enter image description here

App.js

<BrowserRouter basename={process.env.PUBLIC_URL}>
        <Sidebar AmplifySignOut={AmplifySignOut} username={userName} />
        <Switch>
          <Route path='/' component={Home} exact />
          <Route path='/bulletinboard' component={BulletinBoard} />
          <Route path='/infohub' component={InfoHub} />
          <Route component={NotFound} />
        </Switch>
</BrowserRouter>
Lance
  • 215
  • 1
  • 6
  • 21

1 Answers1

0

add a _redirects file in your pubic folder(in react main project)

and add this code in that file

/*    /index.html   200 
Dhruv Kothari
  • 103
  • 2
  • 7
  • does the ```_redirects``` file has no extension or anything? I just tried creating it with the single line of code in my public folder but the result is still the same. – Lance Aug 08 '21 at 04:36
  • no it do not have any extension refer this question https://stackoverflow.com/questions/55990467/catch-all-redirect-for-create-react-app-in-netlify – Dhruv Kothari Aug 08 '21 at 11:39
  • unfortunately it is still not working even after building the app with ```_redirects``` file – Lance Aug 19 '21 at 01:00
  • Any solutions so far @Lance ? – bnays mhz Oct 31 '22 at 16:04