
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
wx-mp-router
Advanced tools
更好用的小程序路由
wx-router
是一个微信小程序路由类,封装了小程序路由 api,并且解决了部分小程序路由 api 中不好用的一些地方,提升开发效率和语义化,以及更优雅的编程体验。
example
文件夹后可以直接放到你的项目中。当然也可以参考 example 的用例。npm install wx-mp-router --save
克隆项目后,小程序工具打开项目指向example
文件夹即可。
import WxRouter from 'wx-mp-router';
export const router = new WxRouter([
{
url: '/pages/index/index',
name: 'Index'
},
{
url: '/pages/home/home',
name: 'Home'
}
]);
需要自己再维护一个路由列表,但是支持 name 跳转
go
-> navigateTo + switchTab不需要区分 tab 页面和非 tab 页面
declare function go(options: {
url?: string;
name?: string;
query?: Record<string, any>;
}): Promise<any>;
router.go({
url: '/pages/index/index',
query: { id: '123', isAuth: true }
});
router.go({
name: 'Index', // 支持别名跳转
query: { id: '123', isAuth: true }
});
goBack
-> navigateBack支持传参
declare function goBack(options: {
delta?: number;
query?: Record<string, any>;
}): Promise<any>;
router.goBack({
delta: 3,
query: { id: '123', isAuth: true }
});
redirect
-> redirectTo也是不需要区分 tab 页面和非 tab 页面
declare function redirect(options: {
url?: string;
name?: string;
query?: Record<string, any>;
}): Promise<any>;
router.redirect({
url: '/pages/index/index',
query: { id: '123', isAuth: true }
});
router.redirect({
name: 'Index', // 支持别名跳转
query: { id: '123', isAuth: true }
});
reLaunch
-> reLaunchdeclare function reLaunch(options: {
url?: string;
name?: string;
query?: Record<string, any>;
}): Promise<any>;
router.reLaunch({
url: '/pages/index/index',
query: { id: '123', isAuth: true }
});
router.reLaunch({
name: 'Index', // 支持别名跳转
query: { id: '123', isAuth: true }
});
onRoute
路由改变钩子,在路由改变时触发,返回一个取消订阅的方法
declare function onRoute(callback: Function): Function;
router.onRoute((e, query) => {
console.log(
e, // 事件
query // 参数
);
});
本项目起因是因为公司项目需求且小程序目前解决方案本人都觉得不优雅而发起的。旨在解决以下场景
当然,以上所有场景都可以用全局状态或者事件总线解决,本人项目也有实现封装(有空再分享),但是并不优雅,页面与页面间耦合度高。
PS.本人在找工作中,有没好的内推介绍一下嘿嘿。
FAQs
a router for Wechat Mini Program
We found that wx-mp-router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.