routerNav.js 659 B

123456789101112131415161718192021
  1. import { err } from '../helpers/warn';
  2. import { formatUserRule, strPathToObjPath } from './util';
  3. /**
  4. * @param {Object} replace vue-router的跳转方式
  5. * @param {Object} rule 需要跳转到的路由匹配规则
  6. * @param {Object} type 对应的官方跳转模式
  7. *
  8. * this 为当前 Router 实例
  9. */
  10. const H5PushTo = function (replace, rule, type) {
  11. if (this.$route == null) {
  12. return err('h5端路由为就绪,请检查调用代码');
  13. }
  14. rule = formatUserRule(rule, this.selfRoutes, this.CONFIG);
  15. const objPath = strPathToObjPath(rule);
  16. objPath.type = type;
  17. this.$route[replace](objPath);
  18. };
  19. export default H5PushTo;