鸿蒙开发学习笔记-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 ...
随机推荐
- 搭建react项目
1.打开新建的项目空文件夹,终端输入命令:npm init,文件夹生成package.json文件: 2.安装webpack.webpack-cli和cross-env:npm install web ...
- openwrt扩容
方法二.三记得先使用Linux系统打开 GParted -- Download 方法三偏移地址获取: 1. 运行的openwrt安装losetup 2. 安装完毕后执行:losetup 获取偏移地址. ...
- day28_常用模块——hashlib,logging模块
hashlib(摘要算法) Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. 什么是摘要算法呢?摘要算法又称哈希算法.散列算法.它通过一个函数,把任意长度的数据转换为一个长度 ...
- [Leetcode 22]生成括号generate parentheses
题目 给定括号对数n,生成所有可能的标准括号结果* *指不能)( https://leetcode.com/problems/generate-parentheses/ Given n pairs o ...
- Ansys-CHEMKIN-pro表面反应机制输入(Surface Kinetics Input)规则
chemkin表面反应机制文件(Ansys-CHEMKIN-pro表面反应机制输入) 1. 文件包含表面活性位(相).表面组分,固相组分.固相,热力学数据,反应机制: 2. 顺序:物质名称,活性位数据 ...
- 小程序使用svga
svga 是一种动画格式.不仅可以在 ios,android,flutter,web 上使用,小程序也支持.设计师使用 after effects 或是 animate 进行动画设计.设计师导出工具 ...
- 118、商城业务---分布式事务---RabbitMQ延时队列定时关单模拟
1.使用RabbitMq实现延时队列方法1 2.基于我们的业务我们使用下面这种方式实现延时队列 1.导入依赖 <dependency> <groupId>org.springf ...
- MQ异常断开
ActiveMQ:No operations allowed after statement closed问题及解决办法 ActiveMQ版本:5.5.1 现象: 系统现象:部分消息发送失败,失败 ...
- [vue2 + jointjs + svg-pan-zoom] 节点自动布局渲染 + 拖拽缩放
启动vue项目,执行以下命令安装dagre.graphlib.jointjs.svg-pan-zoom. npm install dagre graphlib jointjs svg-pan-zoom ...
- jwt auth0 和 jsonwebtoken比较
参考: https://blog.csdn.net/lizz861109/article/details/104614942/