我创建了一个应用程序 Create React App更具体地说,我也在使用 typescript 。
我不知道如何设置绝对路径来访问我的组件、页面等。
在不同的情况下,我会用以下内容更新我的 tscongig:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@components/*": ["src/components/*"]
}
}
}
但我不知道如何实现这一点,因为我正在使用
react-scripts
任何的想法?
最佳答案
创建一个 tsconfig.json 文件并添加以下代码。
{
"compilerOptions": {
"baseUrl": "src"
},
"include": [
"src"
]
}
然后您可以将您的组件导入为
import Header from 'components/Header';
关于reactjs - 将绝对路径添加到由 "Create React App"创建的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55219307/