import { Router } from '../../../lib/utils/router/index'
import UserLogin from '../../login'

class MyRouter extends Router {
  constructor() {
    super()
    this.init()
    this.instance = null
  }

  static getInstance() {
    if (!this.instance) {
      this.instance = new MyRouter()
    }
    return this.instance
  }

  init() {
    this.interceptor = {
      before: _options => {
        // 该页面是否需要登录
        if (_options.needLogin) {
          if (!UserLogin.checkIfLogin()) {
            return false
          }
        }
        return _options
      },
      after: null
    }
  }
}

let _myRouter = MyRouter.getInstance()
export default _myRouter
