WDRouterRule.ets
1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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);
}
}
}