我正在运行npm进行测试,以查看我正在从事的学校项目的工作情况。我收到此错误,并在找到“ app”一词的所有地方都进行了注释。
这是错误:
Syntax error: Identifier 'App' has already been declared (11:7)
9 | import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
10 |
> 11 | const App = () => (
| ^
12 | <Router>
13 | <div>
14 | <ul>
这是文件清单中关联的代码:
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import About from './screens/About';
import Characters from './screens/Characters';
import Home from './screens/Home';
import { BrowserRouter as Router, Route, Link } from 'react-router-dom';
const App = () => (
<Router>
<div>
<ul>
<li>
<Link to='/'>Home</Link>
</li>
<li>
<Link to='/about'>About</Link>
</li>
<li>
<Link to='/characters'>Characters</Link>
</li>
</ul>
<hr />
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
<Route path="/characters" component={Characters} />
</div>
</Router>
);
ReactDOM.render(<App />, document.getElementById('root'));
我不知道还能尝试什么。
我有一个名为app的类并将其注释掉,我不确定在我的项目中标识符app的其他位置。
答案 0 :(得分:4)
标识符App
已在以下行中声明:import App from './App';
我建议更改函数名称,例如:
const MyApp = () => (
...
);
ReactDOM.render(<MyApp />, document.getElementById('root'));
(函数的名称取决于您)