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

fix: Fix the judgment logic of isHomePage in QIANKUN #11265

Closed
wants to merge 3 commits into from
Closed
Changes from 2 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
8 changes: 6 additions & 2 deletions packages/plugin-docs/client/theme-doc/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import cx from 'classnames';
import React, { Fragment, useEffect, useState } from 'react';
import { Helmet } from 'react-helmet';
// @ts-ignore
import { useLocation } from 'umi';
import Announcement from './components/Announcement';
import { ThemeContext } from './context';
import Head from './Head';
Expand Down Expand Up @@ -31,10 +33,12 @@ export default (props: any) => {
}, []);

const { title, description } = props.themeConfig;

const location = useLocation?.();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个地方为啥要 ?. 调用,会不存在吗

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

会的。没有加的话测试用例报错。如果使用了 mpa 模式也会出问题。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

后面 umi 文档应该要迁移到 dumi ,这个地方感觉不太优雅。

Copy link
Contributor Author

@fengsx fengsx Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前用 try-catch 搞了一个版本,感觉太丑了,就换成可选链了。

要不先合了?如果微前端部署的话,home page 判断错误,永远跳不了主页了。

const isHomePage =
window.location.pathname === '/' ||
window.location.pathname.replace(/[a-z]{2}-[A-Z]{2}\/?/, '') === '/';
window.location.pathname.replace(/[a-z]{2}-[A-Z]{2}\/?/, '') === '/' ||
location?.pathname === '/' ||
location?.pathname.replace(/[a-z]{2}-[A-Z]{2}\/?/, '') === '/';

return (
<ThemeContext.Provider
Expand Down