I'm using react-router-dom inside a react app with server side rendering, and I'm looking for a way to obtain something similar to document.location.origin
, but I'm unable to find anything but the pathname. Is there any way to obtain the origin using react-router-dom? Or any other way?
Asked
Active
Viewed 9,939 times
4

Marina Popa
- 77
- 2
- 5
-
Possible duplicate of https://stackoverflow.com/q/42253277/5832644 – tuan.tran Feb 09 '18 at 08:35
-
@TuấnTrầnDuy it's not the same, I'm not looking for the pathname – Marina Popa Feb 09 '18 at 08:42
1 Answers
0
- For the client side
Has tested that the following code works:
let url = `${window.location.origin.toString()}/path/another.html`;
- For the server side
Depending on the server you use, you can get the path information from the request and then pass it to React, for example, if you are using Express.js, you can get the original url with:
let url = req.originalUrl;

tyolab
- 377
- 3
- 11
-
Depending on the server you use, you get can get those path information from request and then pass them to React, for example, if you are using Express.js, you can get the original url with: req.originalUrl – tyolab Dec 05 '20 at 00:30