Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: 补充在路由中使用图标集的文档 #12602

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions docs/docs/docs/api/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,36 @@ import { Icon } from 'umi';
<Icon icon="local:umi" />
```

## 在路由中使用

如需在路由中使用图标集,需要在 `include` 中配置要使用的 icon,可以这样使用。

```ts
function getIcons(routes) {
const icons = new Set<string>()
routes.forEach(v => {
if (v.icon && v.icon.includes(':')) icons.add(v.icon)
if (v.routes) getIcons(v.routes).forEach(v => icons.add(v))
})
return [...icons]
}

export default {
...
icons: {
autoInstall: {},
include: [...getIcons(routes)],
},
...
}
```

```ts
// routes
[{ path: '/xxx', component: 'xxx', icon: 'fa:home' }]

```

### 配置项介绍

- `autoInstall` 表示是否自动安装 icon 集;tnpm/cnpm 客户端暂不支持,但可以通过手动按需安装对应 icon 集合包 `@iconify-json/collection-name` 。 参考:[Icon 集合列表](https://github.com/iconify/icon-sets/blob/master/collections.md), collection-name 为列表中的 ***Icon set prefix*** 项。
Expand Down