鸿蒙开发学习笔记-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 ...
随机推荐
- Day15-static、抽象类、接口、内部类
static.抽象类.接口.内部类 一.static关键字详解 1.静态的变量/方法 package Demo02; //static public class Student { private s ...
- opencv实战之透视变换
import cv2 import numpy as np import pytesseract def cv_show(imgname,img): cv2.imshow(imgname,img) c ...
- Educational Codeforces Round 2 个人总结A-E
Educational Codeforces Round 2 A. Extract Numbers 简单的模拟 bool check(string op) { if(op.size()==1& ...
- RabbitMq的部署(docker)和操作(python)详解
一.简介: RabbitMq 是实现了高级消息队列协议(AMQP)的开源消息代理中间件.消息队列是一种应用程序对应用程序的通行方式,应用程序通过写消息,将消息传递于队列,由另一应用程序读取 完成通信. ...
- 3html5
<label>网址:</label><input type="url" name="" required><br> ...
- Delaunay triangulation 的实现
在GitHub 找到的别人的代码:https://github.com/earthwjl/DelaunayTriangulate 解压后是这样的:(没有x64) 直接就有了.sln工程文件,于是用Vi ...
- SDC细节归纳
能否写出一份严谨的SDC约束文件,决定了芯片tapeout后数字电路能否正常工作,或者少一些bug.所以写好SDC约束文件,是芯片设计的关键一步. 因此,归纳.整理SDC约束的细节要点很重要,有助于减 ...
- C# 将实体转xml/xml转实体
xml转实体 /// <summary> /// 把xml转换成实体 /// </summary> /// <typeparam name="T"&g ...
- git 本地项目初始化提交至仓库
命令行指令 Git初始化配置 git config --global user.name"abc" git config --global user.email"1234 ...
- excel编辑受限的密码保护破解
录制一个宏并且执行: Public Sub 工作表保护密码() Const DBLSPACE As String = vbNewLine & vbNewLine Const AUTHORS A ...