Skip to content

Commit

Permalink
Merge pull request #90 from hiui-group/hotfix/#88
Browse files Browse the repository at this point in the history
Hotfix/#88
  • Loading branch information
solarjoker authored Jan 11, 2022
2 parents f1e8cdd + 698adf9 commit e26b293
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 18 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# 更新日志

## 3.7.0

- 添加 disabledAutoFallback props,支持禁用自动 fallback 到第一个有效路由 [#88](https://github.com/XiaoMi/hiui/issues/88)
- 优化 支持 React.lazy 模式和 keepAlive 模式兼容 [#87](https://github.com/XiaoMi/hiui/issues/87)

## 3.6.0

- 添加 unmountOnTagClose props,支持 keepAlive 模式下点击 tag 关闭触发组件实例销毁 [#85](https://github.com/XiaoMi/hiui/issues/85)
- 添加 unmountOnTagClose props,支持 keepAlive 模式下点击 tag 关闭触发组件实例销毁 [#85](https://github.com/XiaoMi/hiui/issues/85)

## 3.5.4

Expand Down
3 changes: 3 additions & 0 deletions examples/theme/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ class App extends Component {
onMenuClick={(item) => {
console.log('item', item)
}}
fallback={'/iot'}
// basename={'basename'}
// disabledAutoFallback
/>
</React.Suspense>
)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hi-ui/classic-theme",
"version": "3.6.0",
"version": "3.7.0",
"description": "Classic theme for HIUI",
"main": "./es/index.js",
"scripts": {
Expand Down
16 changes: 10 additions & 6 deletions src/components/Layout/ClassicLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const ClassicLayout = ({
login,
toolbar,
fallback,
disabledAutoFallback,
siderTopRender,
siderBottomRender,
footer,
Expand All @@ -44,7 +45,8 @@ const ClassicLayout = ({
location,
history,
fallback,
onMenuClick
onMenuClick,
disabledAutoFallback
)
const isWithoutLayout = currentMenu && currentMenu.withoutLayout
const activeMainMenu = selectedMenus[0]
Expand Down Expand Up @@ -137,11 +139,13 @@ const ClassicLayout = ({
/>
) : null
})}
<Redirect
to={{
pathname: location.pathname === '/' ? defaultPath : fallback || defaultPath
}}
/>
{typeof fallback === 'string' || typeof defaultPath === 'string' ? (
<Redirect
to={{
pathname: location.pathname === '/' ? defaultPath : fallback || defaultPath
}}
/>
) : null}
</Switch>
</div>
{footer && <Footer footer={footer} />}
Expand Down
16 changes: 10 additions & 6 deletions src/components/Layout/GenuineLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const GenuineLayout = ({
login,
toolbar,
fallback,
disabledAutoFallback,
siderTopRender,
siderBottomRender,
footer,
Expand All @@ -43,7 +44,8 @@ const GenuineLayout = ({
location,
history,
fallback,
onMenuClick
onMenuClick,
disabledAutoFallback
)
const isWithoutLayout = currentMenu && currentMenu.withoutLayout

Expand Down Expand Up @@ -135,11 +137,13 @@ const GenuineLayout = ({
/>
) : null
})}
<Redirect
to={{
pathname: location.pathname === '/' ? defaultPath : fallback || defaultPath
}}
/>
{typeof fallback === 'string' || typeof defaultPath === 'string' ? (
<Redirect
to={{
pathname: location.pathname === '/' ? defaultPath : fallback || defaultPath
}}
/>
) : null}
</Switch>
</div>
{footer && <Footer footer={footer} />}
Expand Down
15 changes: 11 additions & 4 deletions src/hooks/useMenuCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { findMenu, getAncestor, getDefaultActiveMenu } from '../util/common'

const reg = /(http|https):\/\/([\w.]+\/?)\S*/gi

const useMenuCalculator = (menu, location, history, fallback, onMenuClick) => {
const useMenuCalculator = (menu, location, history, fallback, onMenuClick, disabledAutoFallback) => {
const getCurrentMenu = useCallback(
(menu) => {
if (menu && menu.length > 0) {
const _currentMenu =
location.pathname === '/'
? findMenu(location.pathname, menu) || getDefaultActiveMenu(menu)
: findMenu(location.pathname, menu) || findMenu(fallback, menu) || getDefaultActiveMenu(menu)
? findMenu(location.pathname, menu) || (disabledAutoFallback ? null : getDefaultActiveMenu(menu))
: findMenu(location.pathname, menu) ||
findMenu(fallback, menu) ||
(disabledAutoFallback ? null : getDefaultActiveMenu(menu))

return _currentMenu
}
Expand Down Expand Up @@ -54,7 +56,12 @@ const useMenuCalculator = (menu, location, history, fallback, onMenuClick) => {
return getCurrentMenu(_menu)
}, [getCurrentMenu, menu])

return { currentMenu, selectedMenus, onSelectMenu, defaultPath: getDefaultActiveMenu(menu).path }
return {
currentMenu,
selectedMenus,
onSelectMenu,
defaultPath: disabledAutoFallback ? null : getDefaultActiveMenu(menu).path
}
}

export default useMenuCalculator
2 changes: 2 additions & 0 deletions src/theme/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const Layout = ({
siderBottomRender,
accordion,
fallback,
disabledAutoFallback = false,
footer,
defaultExpandAll,
pageHeader,
Expand Down Expand Up @@ -98,6 +99,7 @@ const Layout = ({
accordion={accordion}
onMenuClick={onMenuClick}
fallback={fallback}
disabledAutoFallback={disabledAutoFallback}
defaultExpandAll={defaultExpandAll}
pageHeader={pageHeader}
onToggle={onToggle}
Expand Down

0 comments on commit e26b293

Please sign in to comment.