WDRouterRule.ets 1.47 KB
import router from '@ohos.router'
import { Action } from 'wdBean'
import { ToastUtils } from 'wdKit'
import { Action2Page } from './Action2Page'
import { WDRouterPage } from './WDRouterPage'

export class WDRouterRule {
  static jumpWithAction(action?: Action) {
    if (!action || !action.type) {
      ToastUtils.showToast("跳转参数异常", 1000);
      return
    }
    let page = Action2Page.get(action);
    WDRouterRule.jumpWithPage(page, action)
  }

   static jumpWithPage(page?: WDRouterPage, params?: object) {
    if (page) {
      if (params) {
        // router.pushUrl({   url: 'pages/routerpage2', , params: params })
        console.log('page.url()==',page.url())
        router.pushUrl({ url: page.url(), params: params })
      } else {
        router.pushUrl({ url: page.url() }).catch((error:Error)=>{
          console.log("err",JSON.stringify(error))//100002  uri is not exist
        })
      }
    } else {
      ToastUtils.showToast("功能开发中", 1000);
    }
  }

  static jumpWithReplacePage(page?: WDRouterPage, params?: object) {
    if (page) {
      if (params) {
        // router.pushUrl({   url: 'pages/routerpage2', , params: params })
        router.replaceUrl({ url: page.url(), params: params })
      } else {
        router.replaceUrl({ url: page.url() }).catch((error:Error)=>{
          console.log("err",JSON.stringify(error))//100002  uri is not exist
        })
      }
    } else {
      ToastUtils.showToast("功能开发中", 1000);
    }
  }


}