0

¿How works urls with React.js?

Hello, I have a question, I am making a web page with react and I have applied a navigation bar using react router, link, etc. and everything works correctly what happens is that if I enter the url manually it does not load the react page, I understand that It happens because I am making a request to a server path that does not exist. How do I get the page to load? Do i have to apply ssr or is there another way? Thank you very much to all.

18th Apr 2020, 7:42 AM
Jonathan Alvarado
Jonathan Alvarado - avatar
4 ответов
+ 5
You need to have the url pattern to match a route so react router knows which component to render for the given route. If you could share an example url and the code for your routes it would make it easier for us to help https://reacttraining.com/react-router/web you can see how it's done on some of the examples: Basic URL Parameters Route Config and probably others
18th Apr 2020, 12:13 PM
Burey
Burey - avatar
+ 2
Next.js has easy way to use react for ssr.
19th Apr 2020, 1:35 AM
Calviղ
Calviղ - avatar
0
I understand but if I write the url the component doesn't render and I get the message cannot get "/login" url in the browser. I have a image with my navigation but I can't paste it here.
18th Apr 2020, 11:59 PM
Jonathan Alvarado
Jonathan Alvarado - avatar
0
For page request from server, you can use window.location.href ="/path/link".
19th Apr 2020, 1:30 AM
Calviղ
Calviղ - avatar