React-admin 标题未显示在导航栏上
React-admin title not displaying on navbar
看起来很简单。如何在导航栏上放置标题?这是我的 App.js:
import React from 'react';
import { Admin, Resource } from 'react-admin';
import { UserList } from './Users';
import { ItemList, ItemEdit, ItemCreate } from './Items';
import { ProductTypeList, ProductTypeEdit, ProductTypeCreate } from './ProductType'
import Dashboard from './Dashboard'
import jsonServerProvider from 'ra-data-json-server';
import dataProvider from './dataProvider';
import ItemIcon from '@material-ui/icons/ViewListRounded';
import ProductTypeIcon from '@material-ui/icons/LocalOffer';
import UserIcon from '@material-ui/icons/Group';
import authProvider from './authProvider'
const App = () => (
<Admin
dashboard={Dashboard}
authProvider={authProvider}
dataProvider={dataProvider} >
<Resource
name="items"
list={ItemList}
edit={ItemEdit}
create={ItemCreate}
icon={ItemIcon} />
{<Resource
name="productTypes"
options={{ label: 'Product Types' }}
list={ProductTypeList}
edit={ProductTypeEdit}
create={ProductTypeCreate}
icon={ProductTypeIcon} />}
<Resource
name="users"
list={UserList}
icon={UserIcon} />
</Admin >
);
export default App;
运行 react-admin 版本 3.4.2。在教程中,它在添加仪表板后显示 "React Admin" 作为标题。但是在使用 npm create-react-app 重新创建一个新的应用程序并完成教程后,我在导航栏中看不到标题。这是开箱即用的东西,还是我需要创建自定义导航栏?
看看docs,试试这个
<Admin
// add the title prop below
title="my page title"
dashboard={Dashboard}
authProvider={authProvider}
dataProvider={dataProvider} >
Train(上图)让我想到了这个组件。我导入它并在其中使用它并设置 title="My Title" 并且它确实显示在导航栏中。也许我误读了文档,但我不记得看到过任何关于 的信息,只是 title= 的属性,如下所示:
<Admin
// layout={CustomLayout}
dashboard={Dashboard}
authProvider={authProvider}
dataProvider={dataProvider} >
<Title title="g3tools Admin" />
<Resource
name="items"
list={ItemList}
edit={ItemEdit}
create={ItemCreate}
icon={ItemIcon} />
但是,谢天谢地,它让我进入了下一步:现在标题显示在导航栏中,但是当我从左侧菜单中选择资源时,资源名称会附加到标题。
关于如何避免将资源标题塞进管理员标题的任何建议?我确定我遗漏了一些明显的东西。选项是:a) 在显示资源标题时在标题后动态添加 space 或破折号,或者 b) 不显示资源标题(我该怎么做?)
我想最终,我宁愿在导航栏的中心有一个面包屑或显示资源标题,但也许我需要一个自定义导航栏??欢迎任何指导。
更新:
我在 the docs for Customizing the AppBar 中看到如何不显示单个资源页面标题:只需从组件中删除 id="react-admin-title" 然后向元素添加文本:
<AppBar {...props}>
<Typography
variant="h6"
color="inherit"
className={classes.title}
>g3tools Admin</Typography>
</AppBar>
看起来很简单。如何在导航栏上放置标题?这是我的 App.js:
import React from 'react';
import { Admin, Resource } from 'react-admin';
import { UserList } from './Users';
import { ItemList, ItemEdit, ItemCreate } from './Items';
import { ProductTypeList, ProductTypeEdit, ProductTypeCreate } from './ProductType'
import Dashboard from './Dashboard'
import jsonServerProvider from 'ra-data-json-server';
import dataProvider from './dataProvider';
import ItemIcon from '@material-ui/icons/ViewListRounded';
import ProductTypeIcon from '@material-ui/icons/LocalOffer';
import UserIcon from '@material-ui/icons/Group';
import authProvider from './authProvider'
const App = () => (
<Admin
dashboard={Dashboard}
authProvider={authProvider}
dataProvider={dataProvider} >
<Resource
name="items"
list={ItemList}
edit={ItemEdit}
create={ItemCreate}
icon={ItemIcon} />
{<Resource
name="productTypes"
options={{ label: 'Product Types' }}
list={ProductTypeList}
edit={ProductTypeEdit}
create={ProductTypeCreate}
icon={ProductTypeIcon} />}
<Resource
name="users"
list={UserList}
icon={UserIcon} />
</Admin >
);
export default App;
运行 react-admin 版本 3.4.2。在教程中,它在添加仪表板后显示 "React Admin" 作为标题。但是在使用 npm create-react-app 重新创建一个新的应用程序并完成教程后,我在导航栏中看不到标题。这是开箱即用的东西,还是我需要创建自定义导航栏?
看看docs,试试这个
<Admin
// add the title prop below
title="my page title"
dashboard={Dashboard}
authProvider={authProvider}
dataProvider={dataProvider} >
Train(上图)让我想到了这个组件。我导入它并在其中使用它并设置 title="My Title" 并且它确实显示在导航栏中。也许我误读了文档,但我不记得看到过任何关于 的信息,只是 title= 的属性,如下所示:
<Admin
// layout={CustomLayout}
dashboard={Dashboard}
authProvider={authProvider}
dataProvider={dataProvider} >
<Title title="g3tools Admin" />
<Resource
name="items"
list={ItemList}
edit={ItemEdit}
create={ItemCreate}
icon={ItemIcon} />
但是,谢天谢地,它让我进入了下一步:现在标题显示在导航栏中,但是当我从左侧菜单中选择资源时,资源名称会附加到标题。
关于如何避免将资源标题塞进管理员标题的任何建议?我确定我遗漏了一些明显的东西。选项是:a) 在显示资源标题时在标题后动态添加 space 或破折号,或者 b) 不显示资源标题(我该怎么做?)
我想最终,我宁愿在导航栏的中心有一个面包屑或显示资源标题,但也许我需要一个自定义导航栏??欢迎任何指导。
更新: 我在 the docs for Customizing the AppBar 中看到如何不显示单个资源页面标题:只需从组件中删除 id="react-admin-title" 然后向元素添加文本:
<AppBar {...props}>
<Typography
variant="h6"
color="inherit"
className={classes.title}
>g3tools Admin</Typography>
</AppBar>