This content originally appeared on DEV Community and was authored by Emmanuel Ifeanyi MECHIE
Absolute Path vs Relative Path?
Absolute Path is when you source for a folder or file from the root either where your system storage start from or where the project start from.
Relative Path is when you try to source for a file or folder taken into consideration where you are currently located in the project structure.
Steps to configure your React project with absolute path.
- Create React App
- Add jsconfig.json
- Import file with absolute path
Create React App
if you already have react app to configure you can skip this step
npx create-react-app app_name
App.js
import Button from "./components/button";
const App = () => {
return (
<div>
<Button />
<Card></Card>
</div>
);
};
export default App;
Add jsconfig.json
in your project add jsconfig.json beside package.json
jsconfig.js
{
"compilerOptions": {
"baseUrl": "src"
},
"exclude": ["node_modules", "build"],
"include": ["src"]
}
for typescript create tsconfig.json
tsconfig.json
{
"compilerOptions": {
"baseUrl": "src"
},
"include": ["src"]
}
Import with absolute path
import Button from "components/button";
const App = () => {
return (
<div>
<Button />
<Card></Card>
</div>
);
};
export default App;
This content originally appeared on DEV Community and was authored by Emmanuel Ifeanyi MECHIE
Emmanuel Ifeanyi MECHIE | Sciencx (2021-10-17T14:15:33+00:00) How to use absolute path in ReactJs. Retrieved from https://www.scien.cx/2021/10/17/how-to-use-absolute-path-in-reactjs/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.