colindamelio / saraswati

2 stars 0 forks source link

Switch to HashRouter #41

Closed JesseNoseworthy closed 5 years ago

JesseNoseworthy commented 5 years ago

Fixes https://github.com/colindamelio/saraswati/issues/40.

BrowserRouter() will work fine locally, but is prone to errors on the server (this means you will not experience any bugs locally, only in Production). HashRouter() is the solution to this problem, as explained here:

SERVER SIDE: HashRouter uses a hash symbol in the URL, which has the effect of all subsequent URL path content being ignored in the server request (ie you send "www.mywebsite.com/#/person/john" the server gets "www.mywebsite.com". As a result the server will return the pre # URL response, and then the post # path will be handled by parsed by your client side react application.

CLIENT SIDE: BrowserRouter will not append the # symbol to your URL, however will create issues when you try to link to a page or reload a page. If the explicit route exists in your client react app, but not on your server, reloading and linking(anything that hits the server directly) will return 404 not found errors.

JesseNoseworthy commented 5 years ago

Please note that 404's should now redirect the user to a homepage. If the goal is to create a 404 page, we should create a new task to address it. 😄

colindamelio commented 5 years ago

It uglifies the URL for sure but it's definitely the easiest solution.

johnathanfong commented 5 years ago

@colindamelio has this been pushed to prod as well?