index.js 681 B

1234567891011121314151617181920212223242526272829303132333435
  1. import { Router } from '../../../lib/utils/router/index'
  2. import UserLogin from '../../login'
  3. class MyRouter extends Router {
  4. constructor() {
  5. super()
  6. this.init()
  7. this.instance = null
  8. }
  9. static getInstance() {
  10. if (!this.instance) {
  11. this.instance = new MyRouter()
  12. }
  13. return this.instance
  14. }
  15. init() {
  16. this.interceptor = {
  17. before: _options => {
  18. // 该页面是否需要登录
  19. if (_options.needLogin) {
  20. if (!UserLogin.checkIfLogin()) {
  21. return false
  22. }
  23. }
  24. return _options
  25. },
  26. after: null
  27. }
  28. }
  29. }
  30. let _myRouter = MyRouter.getInstance()
  31. export default _myRouter