• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (C) 2024 Huawei Device Co., Ltd.
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14*/
15import {RouterModule} from "RouterModule/src/main/ets/components/mainpage/RouterModule";
16
17@Builder
18export function harBuilder(value: object) {
19  NavDestination(){
20    Column(){
21      Button($r("app.string.to_index"), { stateEffect: true, type: ButtonType.Capsule })
22        .width('80%')
23        .height(40)
24        .margin(20)
25        .onClick(() => {
26          let routerName = "HapA_Router";
27          RouterModule.clear(routerName);
28        })
29      Button($r("app.string.to_hara"), { stateEffect: true, type: ButtonType.Capsule })
30        .width('80%')
31        .height(40)
32        .margin(20)
33        .onClick(() => {
34          let url = "harA/src/main/ets/components/mainpage/HarA-HapA_Router-HarA_Builder";
35          RouterModule.push(url);
36        })
37    }.width('100%').height('100%')
38  }.title('HarB')
39  .onBackPressed(() => {
40    RouterModule.pop("HapA_Router");
41    return true;
42  })
43}
44
45export function harInit(){
46  let builderName = 'HarB_Builder';
47  if(!RouterModule.getBuilder(builderName)){
48    let builder: WrappedBuilder<[object]> = wrapBuilder(harBuilder);
49    RouterModule.registerBuilder(builderName, builder);
50  }
51}
52
53// 自执行函数,在首次引用时触发,将builder注册到RouterModule中
54harInit();