React组件可以用数字命名吗?
Can react components be named with numbers?
不记得在哪里,我看到过这样一个使用404组件的路由器
<Route component={404}/>
我试过创建组件
const 404 = props => {
return (<h1>This is a 404 page!</h1>)
}
它甚至无法编译。我正在使用 create-react-app 和 React Router。
React 只是 JavaScript,变量名不能以数字开头或只能是数字。请参阅下面的 link
What characters are valid for JavaScript variable names?
我建议改为按其含义命名,即 <NotFound />
没有。 JavaScript变量不能以数字开头。
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types
您可以将错误组件命名为 Error404
不记得在哪里,我看到过这样一个使用404组件的路由器
<Route component={404}/>
我试过创建组件
const 404 = props => {
return (<h1>This is a 404 page!</h1>)
}
它甚至无法编译。我正在使用 create-react-app 和 React Router。
React 只是 JavaScript,变量名不能以数字开头或只能是数字。请参阅下面的 link
What characters are valid for JavaScript variable names?
我建议改为按其含义命名,即 <NotFound />
没有。 JavaScript变量不能以数字开头。
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types
您可以将错误组件命名为 Error404