简体   繁体   English

导入时不指定react.js中的索引

[英]Import without specifying index in react.js

How can I configure my react application so I do not need to specify index on my imports? 如何配置我的react应用程序,这样我就不需要在导入中指定索引了?

-src
|- app.jsx
|- views
 |- sample
  |- sample.css
  |- sample-container.jsx
  |- sample-view.jsx
  |- index.jsx

Currently I have to do this: 目前,我必须这样做:

import Sample from "src/views/sample/index"

What I want to do is this: 我想做的是这样的:

import Sample from "src/views/sample"

I used create-react-app for initial set up and already ran npm run eject 我使用create-react-app进行初始设置,并且已经运行了npm run eject

Looks to be an issue with creating new index.jsx file while the server is started. 在服务器启动时创建新的index.jsx文件index.jsx是一个问题。 Shutting down the server and starting it back up ( npm start ) seems to resolve the issue. 关闭服务器并重新启动服务器( npm start )似乎可以解决该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM