我如何为其添加显示名称?
export default () => <Switch> <Route path="/login" exact component={LoginApp}/> <Route path="/faq" exact component={FAQ}/> <Route component={NotFound} /> </Switch>;
直接导出箭头函数不会给组件提供displayName,但如果导出常规函数,则函数名称将用作displayName。
displayName
export default function MyComponent() { return ( <Switch> <Route path="/login" exact component={LoginApp}/> <Route path="/faq" exact component={FAQ}/> <Route component={NotFound} /> </Switch> ); }
您还可以将函数放在变量中,displayName手动设置该函数,然后将其导出。
const MyComponent = () => ( <Switch> <Route path="/login" exact component={LoginApp}/> <Route path="/faq" exact component={FAQ}/> <Route component={NotFound} /> </Switch> ); MyComponent.displayName = 'MyComponent'; export default MyComponent;