鸿蒙开发学习笔记-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 ...
随机推荐
- lightgbm与贷款违约预测项目
lightgbm histogram算法 将连续的浮点值离散成k个离散值,构造宽度为k的histogram leaf-wise生长策略 每次在所有叶子中找到分裂增益最大的一个叶子,一般也是数据量最大的 ...
- PHP Redis - List (列表)
Redis列表是简单的字符串列表,按照插入顺序排序. 一个列表最多可以包含 232-1 个元素 (4294967295, 每个列表超过40亿个元素) 插入元素在列表头部(lPush,Lpushx) ...
- Vue-数据代理
Vue中的数据代理 数据代理定义 所谓数据代理,就是通过一个对象代理对另一个对象中的属性的操作(读/写).说白了就是操作一个对象上的属性可以读取和修改另一个对象上的属性,这种关系就叫做数据代理. 在V ...
- mysql 参数配置
https://www.jb51.net/article/48082.htm https://www.cnblogs.com/angryprogrammer/p/6667741.html
- Leetcode 199
199. Binary Tree Right Side View Given the root of a binary tree, imagine yourself standing on the r ...
- jquery.axios
概念:通过 HTTP 请求加载远程数据. *注:所有的选项都可以通过$.ajaxSetup()函数来全局设置. 回调函数:要处理$.ajax()得到的数据,则需要使用回调函数.beforeSend.e ...
- gulp技术:自动化构建工具
作用:压缩css.js.img,合并文件,改名字,编译sass,拷贝 使用步骤: 1.安装node环境,下一步,下一步,安装C盘: 2.在你的根目录下,在地址栏输入cmd回车: 3.检测node和np ...
- 常用功能系列---【JWT生成Token实现接口登录认证方案思路】
JWT生成Token实现接口登录认证方案思路 方案一(双token实现无感刷新) 在token中,refreshToken的作用主要是避免token过期时,前端用户突然退出登录,跳转至登录页面. 但是 ...
- C/C++ 数据结构循环队列的实现
#include <iostream> #include <Windows.h> using namespace std; #define MAXSIZE 6 typedef ...
- Cross Site Scripting DOM (XSS) 攻击jQuery append() 的处理方法
做安全红线使用Fortify工具进行扫描时,jquery append会报Cross Site Scripting DOM风险.解决该问题有两种办法. 一.原生dom方式 使用JavaScript原生 ...