Skip to content

🧐[问题 | question] config.ts 和 defaultSetting.ts 内 layout.title 生效情况 #11466

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

Open
OtaconBYF opened this issue May 9, 2025 · 0 comments

Comments

@OtaconBYF
Copy link

OtaconBYF commented May 9, 2025

🧐 问题描述 | Problem description

  • 开发环境下 (yarn start) ,登录过后,config.ts 内的 layout.title 会生效
  • 生产环境下 (yarn build), 登录过后,一直是 defaultSetting 里面的title

问题:是不是在开发环境和生产环境,二者的覆盖优先级不同?还是我哪里理解错误了?

💻 示例代码 | Sample code

config/config.ts 中的代码片段

  title: '读取中...',
  /**
   * @name layout 插件
   * @doc https://umijs.org/docs/max/layout-menu
   */
  layout: {
    locale: true,
    ...defaultSettings,
    title: process.env.SITE_TITLE || 'Default Title',
  },

config/defaultSetting.ts 中的代码片段

title: 'Default',

🚑 其他信息 | Other information

config.ts 中可以读取使用 process.env,但 defaultSetting.ts 中不可以,只能写死。所以目前的情况是开发环境下,可以正确使用 config.ts 中定义的,从环境变量SITE_TITLE中读取的 title; 生产环境就只能使用到 defaultSetting.ts 里面写死的 title

临时解决方案 | Workaround

方案1

在app.tsx中,找到如下代码片段(2处),覆盖掉defaultSetting里面的title

settings: defaultSettings as Partial<LayoutSettings>,

改为

settings:{
 ...defaultSettings,
 title: SITE_TITLE,
} as Partial<LayoutSettings>,

方案2

在 defaultSetting 中删掉 title 属性,并在登录页面 pages/Users/Login 中删除使用到这个defaultSetting.title 属性的地方

{Settings.title && ` - ${Settings.title}`}  // 删除这行
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

1 participant