DEV Community

Cover image for Absolute path in React
Hidayt Rahman
Hidayt Rahman

Posted on

4

Absolute path in React

Why we need Absolute path in the App?

Problems
Working on applications without spending much time on organising a folder structure is a common story of the most of the developer as it requires granular details and sometimes we don't create folder structure perfectly because of the early stage of the app.
And most of time its nightmare when we change the folder structure after finishing or middle in the app.
It's painful to change the path for all the affected files relatively.

Solution
So here is the solution of Absolute path.

Absolute path help us to not care about the folder structure changes even in the middle of development or frequent folder structure changes as it can access files from the root folder (as per the configuration)

Relative path vs Absolute path

Relative path : ../../SubFolder/File
Absolute path: components/Folder/SubFolder/File

How to setup in React?

Go to the root folder and create a file jsconfig.json for JS based react app.
and put the configuration into the file

{
  "compilerOptions": {
    "baseUrl": "src"
  },
  "include": ["src"]
}
Enter fullscreen mode Exit fullscreen mode

Try to restart the server and now you can access your files by the full path

components/Folder/SubFolder/File
Enter fullscreen mode Exit fullscreen mode

tsconfig.json (already created in the TypeScript template) at the root of your project

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (0)

SurveyJS custom survey software

Build Your Own Forms without Manual Coding

SurveyJS UI libraries let you build a JSON-based form management system that integrates with any backend, giving you full control over your data with no user limits. Includes support for custom question types, skip logic, an integrated CSS editor, PDF export, real-time analytics, and more.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay