acdlite / redux-router

Redux bindings for React Router – keep your router state inside your Redux store
MIT License
2.3k stars 216 forks source link

Browser refresh not working #205

Closed ochowie closed 8 years ago

ochowie commented 8 years ago

When running the basic example it is not possible to refresh the page when not on the top level route. I get the following error:

Error response

Error code 404.

Message: File not found.

Error code explanation: 404 = Nothing matches the given URI.

This doesn't happen when the route is at '/'.

I am executing the basic example using python's SimpleHTTPServer.

silvenon commented 8 years ago

SPAs (Single Page Applications) that use HTML5 History won't work with a simple HTTP server after a refresh. I'm no server expert, but here's a quick explanation:

When you are at /, the server knows that it should load /index.html. But when you navigate to, say, /foo and refresh, the server will look for /foo/index.html and it won't find it, because the only HTML file you do have is /index.html, the views are generated dynamically.

You need to redirect all requests to /index.html, like this example does here. Then when you go to /foo, the server will load /index.html and by reading the URL it will figure out which view to load.

If you really want to use the simple HTTP server, you can always switch to createHashHistory.

ochowie commented 8 years ago

I can confirm that changing to hash history works.

sators commented 8 years ago

See http://stackoverflow.com/questions/17504959/express-routing-html5-style-catchall-conundrum-no-hashbangs-angular-js-yeoman/34367457#34367457