FormidableLabs / redux-little-router

A tiny router for Redux that lets the URL do the talking.
MIT License
1.04k stars 114 forks source link

Question: <Link>, path and reload/refresh #160

Closed ChrisLMerrill closed 7 years ago

ChrisLMerrill commented 7 years ago

I have the very basics working with redux-little-router - I've basically cloned the demo. I'm new to react, redux and rlr. My (very simple) app has some links, which change the URL and then the content displayed. But using that URL directly or pressing the refresh button results in a 404.

E.g.

  1. app starts at mydomain.com/index.html
  2. user presses link
  3. link changes to mydomain.com/path1
  4. press refresh button -- get 404

I understand that the webserver has no clue what /path1 is...thus the 404. I think I know how to solve it on my webserver (serving the index.html for /*) but not sure how to solve it in my dev environment (I'm using yarn and webpack-devserver).

My question is: Am I missing something else? How do you usually solve this problem? Is this outside the scope of rlr?

TIA! Chris

mhink commented 7 years ago

It sounds like you need to set historyApiFallback: true in your Webpack config. Here are the docs:

https://webpack.js.org/configuration/dev-server/#devserver-historyapifallback

Let me know if that fixes your problem!

nkpz commented 7 years ago

mhink's answer is good for webpack dev server.

I think you've got the gist of it. The steps can vary depending on your configuration.

I'm building an app that's currently served from a Laravel backend (which handles login + api), and I've configured the Laravel router to serve my redux app for anything starting with /app/. This way, 404s on the Laravel app still work properly. I could have also done this at the nginx level.

It's kind of up to you. Because of the infinite variations on server configurations, I would say these issues are within the scope of the server you're using.

tptee commented 7 years ago

I think @mhink 's solution should fix your problem! Like @nnjpp said, this can vary depending on your server/configuration, but definitely works for WDS.