I am working on a ReactJS project and need to set up custom paths for my routes. I want to define my own paths instead of relying on the default routes generated by React Router. What is the best way to achieve this in a React application?
Here’s a simplified version of my current project structure:
/src
/components
Home.js
About.js
/pages
HomePage.js
AboutPage.js
App.js
index.js
3
Answers
Step 1 :
Step 2 : insert this code on app.jsx
1 단계 :
npm install react-router-dom
In order to implement routes to your React app you will need to install
react-router-dom
which will handle the route definition for your applicationIf you are looking for a general guide on what would be the best idea for creating routes, I would recommend viewing the react-router-dom documentation here
From here you can decide what router would work best for the intent of your app and implement from there. Generally speaking, most devs implement
<BrowserRouter>
to use full URLs within your app. Here is an excerpt from the documentationI believe this is as far as I can help you without a more directed approach into what exactly you are looking for. Hope this helps