Steps to Setup ReactJS Application
Step 1: Create a reactJS application by using this command
npx create-react-app url-reader
Step 2: Navigate to the Project folder
cd url-reader
Step 3: Install the necessary packages/libraries in your project using the following commands.
npm install react-router-dom
Project structure:
The updated dependencies in package.json file will look like:
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.3",
}
These are the following methods:
Table of Content
- Using window.location
- Using useLocation hook
How to Read the Current full URL with React?
In React applications, it is often necessary to read the current full URL for various purposes, such as routing, conditional rendering, or logging. There are two common approaches to achieve this: using the window.location
object and using the useLocation
hook from react-router-dom
.