4

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?

Marina Popa
  • 77
  • 2
  • 5

1 Answers1

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