Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read the current URL in the react application

I would like read and print the current URL in the react application. Right now i am using "window.location.pathname" to read the URL but would like to know if there is a better way or some react way to read the URL

like image 476
Phani Avatar asked Aug 23 '18 15:08

Phani


1 Answers

window.location.href

returns the href (URL) of the current page

window.location.hostname

returns the domain name of the web host

window.location.pathname

returns the path and filename of the current page

window.location.protocol

returns the web protocol used (http: or https:)

like image 69
Ashley Fernandes Avatar answered Nov 14 '22 18:11

Ashley Fernandes