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

[Bug] plugin-layout 路由配置 #7100

Closed
TinsFox opened this issue Aug 2, 2021 · 2 comments
Closed

[Bug] plugin-layout 路由配置 #7100

TinsFox opened this issue Aug 2, 2021 · 2 comments

Comments

@TinsFox
Copy link

TinsFox commented Aug 2, 2021

What happens?

plugin-layout 动态菜单图标无法正确显示

Mini Showcase Repository(REQUIRED)

Please provide a repository using yarn create @umijs/umi-app then upload to your GitHub 请提供一个可复现的仓库,使用 yarn create @umijs/umi-app 创建,并上传到你的 GitHub 仓库

按照 https://umijs.org/zh-CN/plugins/plugin-layout 中的扩展的路由配置,我配置一个动态菜单,希望菜单中带有icon,应该是配置icon 字段,赋予该字段一个string 类型的值

icon name 为 组件名小写后去掉 outlined 或者 filled 或者 twotone,所得值。举例: 的 icon name 即: user

也就是说我希望展示 <SmileOutlined/> 的时候给icon 赋值smile 即可,但是实际上展示出来的是smile文本,而不是图标,user
同理
复现代码

const loopMenuItem = (menus) =>
  menus.map(({ icon, children, ...item }) => ({
    ...item,
    // icon: <SmileOutlined/>,
    icon: 'smile',
    children: children && loopMenuItem(children),
  }));

export const layout = ({ initialState }) => {
  return {
    menu: {
      // 每当 initialState?.currentUser?.userid 发生修改时重新执行 request
      locale: false,
      params: initialState,
      // TODO 第一次菜单渲染空
      request: async () => {
        console.log('菜单数据', initialState?.currentRouters)
        return initialState?.currentRouters || defaultMenuData;
      },
    },
  };
};

复现效果图
image

可以达到目标的方案

const loopMenuItem = (menus) =>
  menus.map(({ icon, children, ...item }) => ({
    ...item,
+ icon: <SmileOutlined/>,
-  icon: 'smile',
    children: children && loopMenuItem(children),
  }));

效果图
image

How To Reproduce

使用antd Pro V5 配置动态菜单数据并传入

因为是在antd Pro V5 中使用,不清楚是哪个引起的错误,有可能是antd Pro V5 也可能是umi或者是ProLayout

Context

  • Umi Version: 3.5.0
  • Node Version: v12.18.3
  • Platform: mac OS 10.13.4
@theecn
Copy link

theecn commented Aug 19, 2021

@TinsFox TinsFox closed this as completed Aug 31, 2021
@weilun0510
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants