Skip to content

Commit

Permalink
fix: 修复TabBar组件demo演示页路由跳转失败问题 (#451)
Browse files Browse the repository at this point in the history
  • Loading branch information
cuicuiworld authored Nov 14, 2022
1 parent 8a30496 commit bd57056
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/packages/tabbar/demo.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ const TabbarDemo = () => {
// href="https://m.jd.com"
icon="cart"
/>
<TabbarItem tabTitle={translated.e51e4582} to="/" icon="my" />
<TabbarItem
tabTitle={translated.e51e4582}
to="/pages/index/index"
icon="my"
/>
</Tabbar>
</div>
</>
Expand Down
9 changes: 5 additions & 4 deletions src/packages/tabbaritem/tabbaritem.taro.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FunctionComponent, useEffect } from 'react'
import { useHistory } from 'react-router-dom'
import Taro from '@tarojs/taro'

import bem from '@/utils/bem'
import Icon from '@/packages/icon/index.taro'
Expand Down Expand Up @@ -65,17 +65,18 @@ export const TabbarItem: FunctionComponent<Partial<TabbarItemProps>> = (
}
const b = bem('tabbar-item')
const bIcon = bem('tabbar-item__icon-box')
const history = useHistory()

useEffect(() => {
if (active && href) {
window.location.href = href
return
}
if (active && to) {
history.push(to)
Taro.navigateTo({
url: to,
})
}
}, [active, history, href, to])
}, [active, href, to])

return (
<div
Expand Down

0 comments on commit bd57056

Please sign in to comment.