鸿蒙开发学习笔记-UIAbility-Router页面跳转接口源码分析
在鸿蒙开发中,UIAbility的跳转使用 router 方法.
在使用的时候需导入
import router from '@ohos.router';
该方法接口成员如下:
1.interface RouterOptions
interface RouterOptions {
url: string; // 跳转页面的Url
params?: Object; // 传给跳转页面的参数params
}
该成员定义RouterOptions基本对象,在进行页面跳转时对应跳转的url和传入的参数params。
2.interface RouterState
interface RouterState {
/**
* Index of the current page in the stack.
* NOTE: The index starts from 1 from the bottom to the top of the stack.
* @since 8
*/
index: number;
/**
* Name of the current page, that is, the file name.
* @since 8
*/
name: string;
/**
* Path of the current page.
* @since 8
*/
path: string;
}
改成员定义RouterState基本对象,分别保存三个页面属性 index,name和path
index:记录当前页面在页面栈中的位置
name:记录当前页面的名称,也是文件名
path:记录当前页面的路径
3.interface EnableAlterOptions
interface EnableAlertOptions {
/**
* dialog context.
* @since 8
*/
message: string;
}
该成员定义EnableAlertOptions对象,具有属性 message:string 保存日志文本
4.function push(options: RouterOptions): void
/**
* Navigates to a specified page in the application based on the page URL and parameters.
* @param options Options.
* @since 8
*/
function push(options: RouterOptions):void;
该方法push接受类型为RouterOptions的参数,并进行页面的跳转和参数传递,返回void。
5.function replace(options: RouterOptions): void
/**
* Replaces the current page with another one in the application. The current page is destroyed after replacement.
* @param options Options.
* @since 8
*/
function replace(options: RouterOptions):void;
该方法replace接受类型为RouterOptions的参数,进行页面的替换和参数传递,返回void。
类似的还有:
6.back()函数,返回上一个页面或者返回指定页面
function back(options?: RouterOptions): void
7.clear()函数,清除所有历史页面,并且仅仅在栈顶保存当前页面
/**
* Clears all historical pages and retains only the current page at the top of the stack.
* @since 8
*/
function clear():void;
8.function getParams(): Object;
/**
* Obtains information about the current page params.
* @returns Page params.
* @since 8
*/
function getParams(): Object;
该getParams方法用于获取页面缓存或者被传入的参数.
***方法使用实例***:
使用两个简单的页面跳转和返回来展示router方法的简单使用
两个页面:
./pages/index.ets
./pages/Second.ets
index.ets代码如下:
import router from '@ohos.router'; @Entry
@Component
struct Index {
@State message: string = 'Hello World' build() {
Row() {
Text(this.message)
Blank()
Button('Next')
.onClick(() => {
router.push({
url: 'pages/Second',
params: {
src: 'Index页面传来的数据',
}
})
}) Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
}
.width('100%')
}
.height('100%')
}
}
Second.ets 代码如下:
import router from '@ohos.router'; @Entry
@Component
struct Second {
@State src: string = router.getParams()?.['src']; build() {
Row() {
Column() {
Text(this.src)
.fontSize(50)
.fontWeight(FontWeight.Bold) Button('Back')
.onClick(() => {
router.back()
})
}
.width('100%')
}
.height('100%')
}
}
鸿蒙开发学习笔记-UIAbility-Router页面跳转接口源码分析的更多相关文章
- Springboot学习04-默认错误页面加载机制源码分析
Springboot学习04-默认错误页面加载机制源码分析 前沿 希望通过本文的学习,对错误页面的加载机制有这更神的理解 正文 1-Springboot错误页面展示 2-Springboot默认错误处 ...
- Java并发包源码学习之AQS框架(四)AbstractQueuedSynchronizer源码分析
经过前面几篇文章的铺垫,今天我们终于要看看AQS的庐山真面目了,建议第一次看AbstractQueuedSynchronizer 类源码的朋友可以先看下我前面几篇文章: <Java并发包源码学习 ...
- Java并发编程笔记之Unsafe类和LockSupport类源码分析
一.Unsafe类的源码分析 JDK的rt.jar包中的Unsafe类提供了硬件级别的原子操作,Unsafe里面的方法都是native方法,通过使用JNI的方式来访问本地C++实现库. rt.jar ...
- Spring笔记(5) - 声明式事务@EnableTransactionManagement注解源码分析
一.背景 前面详解了实现Spring事务的两种方式的不同实现:编程式事务和声明式事务,对于配置都使用到了xml配置,今天介绍Spring事务的注解开发,例如下面例子: 配置类:注册数据源.JDBC模板 ...
- Dubbo入门到精通学习笔记(十九):MySQL源码编译安装、MySQL主从复制的配置
文章目录 MySQL 源码编译安装(CentOS-6.6+MySQL-5.6) 一.服务器配置: 二.源码安装 MySQL5.6.26: MySQL主从复制的配置 环境 依赖课程 MySQL 主从复制 ...
- Django基于Pycharm开发之四[关于静态文件的使用,配置以及源码分析](原创)
对于django静态文件的使用,如果开发过netcore程序的开发人员,可能会比较容易理解django关于静态文件访问的设计原理,个人觉得,这是一个middlerware的设计,但是在django中我 ...
- Linux学习笔记15—RPM包的安装OR源码包的安装
RPM安装命令1. 安装一个rpm包rpm –ivh 包名“-i” : 安装的意思“-v” : 可视化“-h” : 显示安装进度另外在安装一个rpm包时常用的附带参数有:--force : 强制安装, ...
- Java并发包源码学习之线程池(一)ThreadPoolExecutor源码分析
Java中使用线程池技术一般都是使用Executors这个工厂类,它提供了非常简单方法来创建各种类型的线程池: public static ExecutorService newFixedThread ...
- 转!!Java学习之自动装箱和自动拆箱源码分析
自动装箱(boxing)和自动拆箱(unboxing) 首先了解下Java的四类八种基本数据类型 基本类型 占用空间(Byte) 表示范围 包装器类型 boolean 1/8 true|fal ...
- Java学习之自动装箱和自动拆箱源码分析
自动装箱(boxing)和自动拆箱(unboxing) 首先了解下Java的四类八种基本数据类型 基本类型 占用空间(Byte) 表示范围 包装器类型 boolean 1/8 true|false ...
随机推荐
- Eclipse 搭建一个简单的SpringBoot+WebSocket环境
WebSocket是一种在单个TCP连接上进行全双工通信的协议. WebSocket通信协议于2011年被IETF定为标准RFC 6455,并由RFC7936补充规范. WebSocket API也被 ...
- 基于Python接口自动化测试持续集成----在jenkins创建任务->检出git的代码-->生成报告-->发送邮件
步骤一:先在jenkins创建一个自由风格的任务 步骤二:然后在源码管理选择git检出代码的方式,需要提供代码所在git的路径和登录git的账号和密码 步骤三:返回到任务配置的界面,先在构建后操作增加 ...
- 【已解决】robotframework 连接oracle数据库返回结果中文显示乱码
问题描述:查询数据库返回信息有中文的时候会显示unicode的样式,如图: 环境:robotframework 3.0.x 解决方法: 找到Python安装目录下的\Lib\site-packages ...
- div 自动滚轮2
HTML: <div class="cal_bottom" style="height:78%;margin-top:2%;overflow:auto;" ...
- springboot配置类@ConfigurationProperties报错Not registered via @EnableConfigurationProperties or marked as Spring component
添加一个@Component可以解决此问题,只有这个组件是容器中的组件,才能使用容器提供的@ConfigurationProperties功能.
- 记安装MySQL数据库
记录一次自己动手安装MySQL数据库所踩的坑 MySQL安装包与操作系统匹配 安装包有amd和Intel,32位.64位多种组合需要确认仔细使用者操作系统和CPU型号 例如我使用的是CentOS ...
- 发布订阅清理distribution未执行导致distribution库特别大处理办法
近期发现数据服务器中数据库所在盘被占用的特别严重,一个800G的盘只剩下不到100G,排除备份所占用的其他的空间竟然有400G被安装目录下的分发数据库distribution.MDF所占用. 分发数据 ...
- 使用 Transformers 在你自己的数据集上训练文本分类模型
最近实在是有点忙,没啥时间写博客了.趁着周末水一文,把最近用 huggingface transformers 训练文本分类模型时遇到的一个小问题说下. 背景 之前只闻 transformers 超厉 ...
- 标题Ubuntu将默认的python3改为默认的python
ryzen@cp7:~$ python Command 'python' not found, did you mean: command 'python3' from deb python3 roo ...
- C/C++ 数据结构循环队列的实现
#include <iostream> #include <Windows.h> using namespace std; #define MAXSIZE 6 typedef ...