1/* 2 * Copyright (c) 2023 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 */ 15 16import { StaticContentPageOne, StaticContentPageDataOne } from './StaticContentPageOne' 17import { StaticContentPageTwo, StaticContentPageDataTwo } from './StaticContentPageTwo' 18import router from '@ohos.router' 19 20 21@Component 22export struct StaticHome { 23 @Provide('pathInfos') pageInfos: NavPathStack = new NavPathStack() 24 25 @Builder 26 PageMap(name: string) { 27 if (name === 'pageOne') { 28 StaticContentPageOne(new StaticContentPageDataOne(name, this.pageInfos)); 29 } else if (name === 'pageTwo') { 30 StaticContentPageTwo(new StaticContentPageDataTwo(name, this.pageInfos)); 31 } 32 } 33 34 build() { 35 Navigation(this.pageInfos) { 36 Column() { 37 Button($r('app.string.home_button_back'), { stateEffect: true, type: ButtonType.Capsule }) 38 .width('80%') 39 .height(40) 40 .margin(20) 41 .onClick(() => { 42 router.back(); 43 }) 44 Button($r('app.string.home_button_page_one'), { stateEffect: true, type: ButtonType.Capsule }) 45 .width('80%') 46 .height(40) 47 .margin(20) 48 .onClick(() => { 49 this.pageInfos.pushPath({ name: 'pageOne' }); //将name指定的NavDestination页面信息入栈 50 }) 51 Button($r('app.string.home_button_page_two'), { stateEffect: true, type: ButtonType.Capsule }) 52 .width('80%') 53 .height(40) 54 .margin(20) 55 .onClick(() => { 56 this.pageInfos.pushPath({ name: 'pageTwo' }); //将name指定的NavDestination页面信息入栈 57 }) 58 } 59 }.title($r('app.string.home_title')).navDestination(this.PageMap) 60 } 61}