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 🙏

© 2024 – Pkg Stats / Ryan Hefner

luo-u-router

v0.0.21

Published

Route monitoring and operation in uniapp.

Downloads

5

Readme

Luo-U-Router

uniapp中的路由监控和操作. 原生跳转方法完全兼容 switchTab点击拦截全兼容 后退及系统返回键拦截全兼容 性能优越

Install

npm install luo-u-router -S

Usage

import Vue from 'vue';
import Router from 'luo-u-router';

let router = new Router({routes: pages});

router.beforeEach((to, from, next) => {
  console.log(to);
  console.log(from);
  // next('/components/TabBarA/index', 'switchTab');
  
  // if (to.path == '/pages/Test/index') {
  //   return next('/pages/Test2/index', 'navigateTo');
  // }

  next();
  // next({path: '/home', query: {dd: 2}});
});

router.afterEach((to, from, redirect, status ) => {
  console.log(to);
  console.log(from);
  console.log(redirect);
  console.log(status);
});

Vue.use(router);

const app = new Vue({
  ...App,
  router
});

app.$mount();

Api

路由拦截

/**
* 前置路由拦截
* @param {Object} [to]         目标对象 (navigateType:为跳转类型)
* @param {Object} [from]       来源对象 
* @param {Function} [next]     放行方法   
*                                 (参数1可选[String]或[Object]: {path: '/xxx', query: {xxx: xxx}})
*                                 (参数2可选[String]navigateType跳转类型, 为空时为默认对应跳转类型})
* @return {undefined}         
*/
router.beforeEach((to, from, next) => {
  console.log(to);
  console.log(from);
  next();
});

/**
* 后置路由拦截
* @param {Object} [to]          目标对象 (navigateType:为跳转类型,当redirect为空时为undefined)
* @param {Object} [from]        来源对象
* @param {Object} [redirect]    重定向对象(无重定向时为空)
* @param {String} [status]      跳转状态(ok:成功 error:失败 timeout:超时)
* @return {undefined}         
*/
router.afterEach((to, from, redirect, status ) => {
  console.log(to);
  console.log(from);
  console.log(redirect);
  console.log(status);
});

路由对象获取

/**
* 跳转后可通过this.$route获取路由信息
*/

/**
* 获取参数
*/
this.$route.query  
/**
* 获取元配置
* [isSub]是否是分包路由
* [isTabBar]是否是tabBar页面
* [TBindex]如果为tabBar页面为tabBar页面索引
*/
this.$route.meta      
/**
* 路由全路径
*/
this.$route.fullPath   
/**
* 页面地址
*/
this.$route.path
/**
* 参数
*/
this.$route.query

示例

/**
* navigateTo跳转 
*/
uni.navigateTo({
  url: '/layouts/Login2/index'
});

uni.navigateTo({
  url: '/layouts/Login2/index?a=1&b=2'
});

/**
* redirectTo跳转 
*/
uni.redirectTo({
  url: '/layouts/Login2/index'
});

uni.redirectTo({
  url: '/layouts/Login2/index?a=1&b=2'
});

/**
* reLaunch跳转 
*/
uni.reLaunch({
  url: '/layouts/Login2/index'
});

uni.reLaunch({
  url: '/layouts/Login2/index?a=1&b=2'
});

/**
* switchTab跳转 
* 可以传参并通过this.$route.query接收参数
*/
uni.switchTab({
  url: '/components/TabBarA/index'
});

uni.switchTab({
  url: '/components/TabBarA/index?xx=777'
});

/**
* 监听switchTab点击并拦截
* 平台全兼容
*/
router.beforeEach((to, from, next) => {
  if (to.navigateType == 'switchTabButton') {
    return next('/home');
  }
  next();
});

/**
* navigateBack跳转 
*/
uni.navigateBack({
  delta: 2
});
/**
* 监听后退及系统返回键并拦截
* 平台全兼容
*/
router.beforeEach((to, from, next) => {
  if (to.navigateType == 'backButton') {
    return next('/home');
  }
  next();
});

pages.json配置示例

/**
* 配置好使用时要解析成一维数组并且path为全路径才能使用
* pages.json和routes要对应,如pages.json有某一路由但解析后的routes里没有则路由跳转时为无效
* routes如果是分包页需要配置meta的isSub为true
* routes如果是tabBar页需要配置meta的isTabBar为true,和meta的TBindex为tabBar索引
*/

{
	"pages": [
		{
			"path": "layouts/Login/index",
			"meta": {"test": "test1"},
			"style": {
				"navigationBarTitleText": "uni-app"
			}
		},
		{
			"path": "layouts/Login2/index",
			"meta": {"test": "test1"},
			"style": {
				"navigationBarTitleText": "uni-app"
			}
		},
	  {
			"path": "components/TabBarA/index"
		},
		{
			"path": "components/TabBarB/index"
		},
		{
			"path": "components/TabBarC/index"
		}
	],
	"subPackages": [
    {
			"root": "pages",
			"pages": [
				{
					"path": "Test/index",
					"meta": {"test": "test2"},
					"style": {
						"navigationBarTitleText": "uni-app"
					}
				},
				{
					"path": "Test2/index",
					"meta": {"test": "test3"},
					"style": {
						"navigationBarTitleText": "uni-app"
					}
				}
			]
		}
	],
	"tabBar": {
    "color": "#7A7E83",
    "selectedColor": "#3cc51f",
    "borderStyle": "black",
    "backgroundColor": "#ffffff",
    "list": [
			{
				"pagePath": "components/TabBarA/index",
				"iconPath": "static/logo.png",
				"selectedIconPath": "static/logo.png",
				"text": "组件"
			}, {
				"pagePath": "components/TabBarB/index",
				"iconPath": "static/logo.png",
				"selectedIconPath": "static/logo.png",
				"text": "接口"
			},
			{
				"pagePath": "components/TabBarC/index",
				"iconPath": "static/logo.png",
				"selectedIconPath": "static/logo.png",
				"text": "个人"
			}
	  ]
  },
}

方法

/**
* await
* 等待是否可以跳转
*/
router.afterEach((to, from, redirect, status ) => {
  if (status === 'no find') {
    router.await(() => {
      uni.redirectTo({url: '/components/Error/index?type=404'});
    });
  }
});

License

This content is released under the MIT License.