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>

1 Answer 1

0

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

and add this code in that file

/*    /index.html   200 
4
  • 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 8, 2021 at 4:36
  • no it do not have any extension refer this question stackoverflow.com/questions/55990467/… Aug 8, 2021 at 11:39
  • unfortunately it is still not working even after building the app with _redirects file
    – Lance
    Aug 19, 2021 at 1:00
  • Any solutions so far @Lance ?
    – bnays mhz
    Oct 31, 2022 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.