I am currently thinking of creating a SPA with Rails as the backend.
I would like to control the /user
screen below when I log in using the browserHistory of react-router
.
In other words, whether you access /user/hoge
, or /user/fuga
, Rails always takes the same action, and we would like to draw using React on the client side.
I'm looking for a lot of things.
I found a way to define the /user/hoge and /user/fuga actions on the controller and use the same view for both.
Note: https://github.com/sugyan/react-router-scaffold
It is true that even if the react-router
changes the URL, it can be reloaded.
But I think this is a bit redundant.
If you increase the number of routes on the client side, you must configure the same route on the server side.
So I tried to see if nginx
could do something like the one described in react-router
.
Note: https://github.com/reactjs/react-router/blob/master/docs/guides/Histories.md#configuring-your-server
location/user/{
try_files$uri/user;
}
After a lot of trial and error, when I wrote it like this, it worked as I wanted.
Now that I've come to that point, I'm wondering if I should use nginx
, so I'm going to ask you a question now.
Is it impossible for Rails to set up a route that performs the specified action without issuing 404 no matter what requests are received below /user
?
Or is there a gem that can be done?
(From comments)
I solved myself.By using get'*anything'
in the routing configuration, we were able to handle all unexpected access with the same action.
© 2024 OneMinuteCode. All rights reserved.