Skip to content

Commit

Permalink
fix(components): 修复h5 tabbar在'/'不展示的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Littly committed Dec 13, 2018
1 parent 93e23f0 commit 8c92c90
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions packages/taro-components/src/components/tabbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import Nerv from 'nervjs'
import classNames from 'classnames'
import './style'

function fixPagePath (pagePath) {
return pagePath.replace(/^\.?\//, '')
}
const removeLeadingSlash = str => str.replace(/^\.?\//, '')
const removeTrailingSearch = str => str.replace(/\?[\s\S]*$/, '')

class Tabbar extends Nerv.Component {
constructor (props) {
super(...arguments)
Expand All @@ -18,7 +18,7 @@ class Tabbar extends Nerv.Component {
throw new Error('tabBar 配置错误')
}

this.homePage = fixPagePath(props.homePage)
this.homePage = removeLeadingSlash(props.homePage)

this.state = {
list,
Expand All @@ -37,27 +37,22 @@ class Tabbar extends Nerv.Component {

getCurrentPathname () {
let pathname
let publicPath
if (this.props.mode === 'hash') {
pathname = location.hash
publicPath = ''
pathname = location.hash.replace('#', '')
} else {
pathname = location.pathname
publicPath = this.props.publicPath
pathname = location.pathname.replace(new RegExp(`^${this.props.publicPath}/?`), '')
}

return pathname.replace(/\?[\s\S]*$/, '').replace(new RegExp(`^#?${publicPath}/?`), '')
return removeTrailingSearch(pathname)
}

hashChangeHandler ({ toLocation } = {}) {
let pathname = ''
let currentPage

if (toLocation) {
pathname = toLocation.pathname
currentPage = pathname ? pathname.replace(/^\//, '') : this.homePage
currentPage = toLocation.pathname ? removeLeadingSlash(toLocation.pathname) : this.homePage
} else {
currentPage = this.getCurrentPathname()
currentPage = this.getCurrentPathname() || this.homePage
}

const stateObj = { isShow: false }
Expand Down

0 comments on commit 8c92c90

Please sign in to comment.