React-router: HistoryLocation doesn't understand Server Redirects to `/#/route`

Created on 16 Jan 2015  路  3Comments  路  Source: ReactTraining/react-router

Currently using Amazon S3 and redirecting from 404s to /#/routename but the HistoryLocation setup doesn't recognise the routes and starts up the defaultRoute every time.

e.g.

/profile -> reload page -> server hits 404 -> server redirects to /#/profile -> react router redirects to /default.

I've read that we should be using RewriteRule style setups on the server but this is seemingly not possible with an Amazon S3 box.

So it would be nice if HistoryLocation could see a match of /#/route and load up /route. I thought this was how it should work so surprised it's not doing.

Most helpful comment

I've found cool way to overcome this with setting up Cloudfront. Basically you need to add custom behaviour for 404 error on cloudfront distribution. I've explained this in detail here

All 3 comments

Haven't used Amazon S3 yet, but this whole 404 and server-side hash redirection situation (didn't even know that was possible) seems a little weird to me :smile:
Anyway, I don't think the router should handle this (at least not by default), since you might want to use the hash for other things when not using HashLocation.

I think you could easily solve this yourself with

// before Router.run
HistoryLocation.replace(HashLocation.getCurrentPath())

Thanks that works a charm :)

I've found cool way to overcome this with setting up Cloudfront. Basically you need to add custom behaviour for 404 error on cloudfront distribution. I've explained this in detail here

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yormi picture yormi  路  3Comments

davetgreen picture davetgreen  路  3Comments

nicolashery picture nicolashery  路  3Comments

maier-stefan picture maier-stefan  路  3Comments

Waquo picture Waquo  路  3Comments