import { createHashHistory  } from 'history'
const history = createHashHistory()
export default history

// 判断是手机端还是pc端
export const isMobiileFu = () => {
  if (window.navigator.userAgent.match(
    /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
  )) {
    return true
  } else return false
}

// 监听路由
let routerLength = 0
history.listen((_: any, listener: any) => {
  if (listener === 'PUSH') {
    routerLength += 1
  } else if (listener === 'POP') {
    if (routerLength >= 1) routerLength -= 1
  }
})

// 点击返回
export const backPageFu = (path: string) => {
  if (routerLength) history.go(-1)
  else history.push(path)
}