上篇回顾: ArkTS开发系列之导航 (2.5.1 页面路由)
本篇内容:主要学习页面内组件导航
一、 知识储备
1. Navigation
- 一般作为页面的根容器,包括单页面、分栏和自适应三种显示模式。
- 自适应模式 (NavigationMode.Auto) ,需要注意的是当设备宽度大于520vp时,Navigation组件采用分栏模式。反之采用单面模式
@Entry @Component struct MyRouter { build(){ Column(){ Navigation(){ ... } .mode(NavigationMode.Auto) } } }
- 单页面模式(NavigationMode.Stack)
- 分栏模式(NavigationMode.Split)
- NavRouter是配合Navigation使用的特殊子组件,默认提供点击响应处理。有且仅有两个子组件,其中第二个子组件必须是NavDestination。
- 常用函数
Navigation() { TextInput({ placeholder: '请输入...' }) .width('90%') .height(40) .backgroundCo