npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ad-router-compiler

v1.0.3

Published

ad-router-plugin

Readme

配置

npm源

查看:npm config get registry

设置: npm config set registry https://registry.npmmirror.com/
https://registry.npmjs.org
https://repo.huaweicloud.com/repository/npm/

1.清理换缓存

npm cache clean --force

2.禁止安全连接

npm config set strict-ssl false

3.修改镜像源

npm config set registry https://registry.npmjs.org

npm config set registry https://registry.npmmirror.com

4.查看是否修改成功

npm config get registry

5.推送 

npm publish --registry=https://registry.npmjs.org/

简介

ADRouter 路由解决方案 解决HSP路由跳转负责的问题 可以在各个page中进行跳转

  • 支持页面间路由跳转;
  • 支持带参数跳转及回调;
  • 支持配置跳转拦截器;
  • 支持拦截器中进行重定向
  • 支持预处理跳转与否。

下载安装

ohpm install ADRouter

OpenHarmony ohpm 环境配置等更多内容,请参考如何安装 OpenHarmony ohpm 包

使用说明

基础配置

注册插件

hvigor/hvigor-config.json5 中添加插件依赖

"dependencies": {
    ……
    "andea-router-compiler": "1.0.1"
},

entry/hvigorfile.ts 注册插件

import { hapTasks } from '@ohos/hvigor-ohos-plugin';
import { adRouterPlugin } from "andea-router-compiler";

export default {
system: hapTasks,  /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[adRouterPlugin()]         /* Custom plugin to extend the functionality of Hvigor. */
}

初始化SDK

建议在AbilityStage中进行初始化

import { AbilityStage } from '@kit.AbilityKit';
import { ADRouter } from '@gzandea.router';


export default class MyAbilityStage extends AbilityStage{


  onCreate(): void {
    ADRouter.getInstance().init(this.context)
  }

}

注册路由

正常创建page页面 然后如下所示,添加routerName 如下所示

@Page({name:"index"})
  • 目前版本不支持正则路由
  • 目前不支持变量/常量引用,请直接使用字符串

路由跳转

1.不传参跳转

ADRouter.getInstance()创建路由对象,使用链式调用方法 build('')配置跳转的页面,navigation() 方法进行页面跳转。

import {ADRouter} from "@gzandea.router";
ADRouter.getInstance()
    .build("--/--")  //需要跳转的地址
    .navigation()

2.传参跳转

在不传参跳转的基础上,跳转之前通过withParams()进行参数配置。

import {ADRouter} from "@gzandea.router";
ADRouter.getInstance()
    .build("--/--")  //需要跳转的地址
    .withParams({index:"--"})
    .navigation()

3.路由回调

路由回调需要配合NavigationResult接口进行,在路由前的页面实现NavigationCallback接口

import {NavigationResult} from '@gzandea.router'
var callback:NavigationResult<T> = {
    onResult(t){},
}

然后设置回调方法 .navigation()中进行跳转

import {ADRouter} from "@gzandea.router";
ADRouter.getInstance()
    .build("--")//需要跳转的地址
    .setOnResult({
         onResult: (t) => {
             .......
         }
    })
    .navigation()

在目标页面中调用getNavigationResult()方法获取到指定的回调类,调用对应的回调方法,即可回调源页面实现的方法

ADRouter.getInstance().getNavigationResult(router.getParams())?.onResult(t)
  • 注意,如果注册了回调,请一定在目标上面上调用getNavigationResult方法,不然会有内存泄漏的问题

路由拦截

1.配置拦截器

在拦截器中的process()方法中实现页面的拦截,通过interceptorCallback.onInterrupt()中断跳转,interceptorCallback.onContinue() 继续跳转。

import {Postcard,IInterceptor,InterceptorCallback} from '@gzandea.router';
var iInterceptor:IInterceptor= {
    process(postcard:Postcard, interceptorCallback:InterceptorCallback) {
        // 选择拦截的页面,若跳转时有该路径则进行拦截提示,若没有则直接跳转
        if (postcard.getUri() == 'pages/transit') {
            // 选择弹框
            AlertDialog.show(
                {
                    message: '被拦截了,点击继续跳转',
                    primaryButton: {
                        value: '取消',
                        action: () => {
                            // 中断跳转
                            interceptorCallback.onInterrupt(postcard)
                        }
                    },
                    secondaryButton: {
                        value: '继续',
                        action: () => {
                            // 继续跳转
                            interceptorCallback.onContinue(postcard);
                        }
                    },
                }
            )
        }else if(postcard.getUri() == 'pages/transit1'){
            //重定向跳转
            interceptorCallback.onContinue(ADRouter.getInstance().build("pages/transit2"));
        }else {
            // 继续跳转
            interceptorCallback.onContinue(postcard);
        }
    }
}

2.注册拦截器

import {registerInterceptor} from '@gzandea.router';
registerInterceptor(iInterceptor);

3.移除拦截器

import {unregisterInterceptor} from '@gzandea.router';
unregisterInterceptor()

4.配置绿色通道

在跳转前使用.setGreenChannel()方法跳过拦截(true:跳过拦截)。

ADRouter.getInstance()
    .build("--/--")//需要跳转的地址
    .setGreenChannel(true)
    .navigation()

5.配置预处理跳转与否

预处理:实现 PretreatmentService 接口中 onPretreatment 方法,并返回一个Boolean值(true:继续跳转,false:不跳转)。

import {PretreatmentService} from '@gzandea.router';
var pretreatmentService:PretreatmentService = {
  onPretreatment(postcard:Postcard):boolean{
    return true
  }
}

在跳转前调用.setPretreatmentService() 方法,将 pretreatmentService传入 setPretreatmentService()方法中完成预处理功能。

ADRouter.getInstance()
    .build(this.router)
    .setPretreatmentService(pretreatmentService)
    .navigationWithCallback(callback)

6.返回到指定页面

ADRouter.getInstance()
    .build("--")
    .back()

接口说明

ADRouter

| 方法名 | 入参 | 接口描述 | |:-----------------------|:--------------------|:----------| | build | string | 配置页面跳转路径 | | withParams | { } | 传入另一页面的参数 | | navigation | | 正常跳转 | | navigationWithCallback | NavigationCallback | 带回调跳转 | | setGreenChannel | boolean | 配置是否为绿色通道 | | registerInterceptor | iInterceptor | 注册拦截器 | | unregisterInterceptor | | 移除所有拦截器 | | getNavigationCallback | | 获取状态回调方法 | | setUri | string | 设置页面跳转路径 | | getUri | | 获取跳转的页面路径 | | getParams | | 获取跳转传递的参数 | | getTag | | 获取标签 | | setTag | { } | 设置标签 | | withFlags | boolean-number | 设置flags | | addFlags | number | 添加flags | | getFlags | number | 获得flags | | back | | 返回页面 | | toString | | 导出字符串 | | setPretreatmentService | PretreatmentService | 预处理 | | setOnResult | NavigationResult | 设置页面回调方法 |

Flags 枚举功能

| 接口名 | 功能描述描述 | |:-------:|:------:| | REPLACE | 替换当前页面 | | SINGLE | 单实例模式 |

回调接口

| 接口名 | 入参 | 接口描述 | |:----------------------------------:|:----------------------------:|:--------:| | NavigationCallback.onArrival | Postcard | 到达回调地 | | NavigationCallback.onInterrupt | Postcard | 回调中断 | | NavigationCallback.onLast | Postcard | 跳转失败 | | NavigationCallback.onFound | Postcard | 找到路由真实地址 | | IInterceptor.process | Postcard,InterceptorCallback | 拦截过程 | | InterceptorCallback.onContinue | Postcard | 拦截器回调继续 | | InterceptorCallback.onInterrupt | Postcard | 拦截器回调暂停 | | PretreatmentService.onPretreatment | Postcard | 预处理实现 | | NavigationResult.onResult | any | 页面回调 |

约束与限制

在下述版本验证通过:

DevEco Studio 5.0.0 Release Build #DS-233.14475.28.36.503910 Build Version: 5.0.3.910, built on November 1, 2024

HarmonyOS 5.0.0 Release SDK, based on OpenHarmony SDK Ohos_sdk_public 5.0.0.71 (API Version 12 Release) Or OpenHarmony SDK Ohos_sdk_public 4.0.10.16 (API Version 10 Release)

目录结构

贡献代码

使用过程中发现任何问题都可以提 Issue 给我,当然,我们也非常欢迎你给我发 PR

开源协议

本项目基于 MIT license ,请自由地享受和参与开源。