Installing React Router
Installation
To begin utilizing the React Router library, we first need to install it in our project using a package manager such as npm or yarn. Open the terminal in the project directory and execute the following command: Using npm:
npm install react-router-dom
Checking Installation
Now that we've installed the react-router-dom
package, let's verify that it has been added to our project successfully. To do this, we'll examine the package.json
file, which lists the project's dependencies.
By default, the dependencies object in package.json
includes only the packages required for running and setting up a plain React project. It may look something like this:
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
After adding the react-router-dom
package, you should observe a modified dependencies object with the react-router-dom
package included (as shown in line 7):
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.13.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
How do I use React Router in my app after installing it?
Can you show me how to set up basic routes with React Router?
What is the next step after installing react-router-dom?
Awesome!
Completion rate improved to 4.17
Installing React Router
Свайпніть щоб показати меню
Installation
To begin utilizing the React Router library, we first need to install it in our project using a package manager such as npm or yarn. Open the terminal in the project directory and execute the following command: Using npm:
npm install react-router-dom
Checking Installation
Now that we've installed the react-router-dom
package, let's verify that it has been added to our project successfully. To do this, we'll examine the package.json
file, which lists the project's dependencies.
By default, the dependencies object in package.json
includes only the packages required for running and setting up a plain React project. It may look something like this:
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
After adding the react-router-dom
package, you should observe a modified dependencies object with the react-router-dom
package included (as shown in line 7):
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.13.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
Дякуємо за ваш відгук!