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

@gowiny/uni-router

v1.0.15

Published

uniapp vue3 版本的 路由守卫,提供beforeEach 和afterEach 2个守卫

Downloads

59

Readme

gowiny-uni-router

详细使用方法,可以查看演示项目

演示项目地址:https://gitee.com/gowiny/uni-example

介绍

uniapp 的 Vue 3版本的 路由守卫
提供 beforeEachafterEach 两个守卫
跳转页面,尽量用官方提供的原生api,如果想用name形式跳转,可以用路由组件提供的以下方法

this.$Router.push = uni.navigateTo
this.$Router.replace = uni.redirectTo
this.$Router.replaceAll = uni.reLaunch
this.$Router.pushTab = uni.switchTab
this.$Router.back = uni.navigateBack

在页面生命周期的事件内,可以调用this.$Route获取当前路由信息
但还是强烈建议,直接用官方提供的 getCurrentPages 方法去获取路由信息

this.$Route //获取当前路由对象
this.$Route.fullPath //完整的路径
this.$Route.path //以/开头的路径
this.$Route.query //参数

//pages.json 里配置page的其他信息,也会附加在此对象里
<router-link name="login" :query="{id:'myid'}">跳转到登录页</router-link>
<router-link path="/pages/index/index" :query="{name:'testname'}">跳转到首页</router-link>

安装教程

  1. 安装:
npm install @gowiny/uni-router
  1. 初始化
  • router/index.ts
import { createRouter,BeforeEachResult } from '@gowiny/uni-router'
import PAGE_DATA from '@/pages.json';

const router = createRouter({
    pageData:PAGE_DATA
})

router.beforeEach((to,from)=>{
    console.log('beforeEach 1 ,',to,from)
})

router.beforeEach((to,from)=>{
    console.log('beforeEach 2 begin',to,from)
	if(to.path != '/pages/login/login'){
        //如果返回的是Promise,则会等待执行完成才进行下一步
        return new Promise<BeforeEachResult>((success,fail)=>{
            setTimeout(function(){
                console.log('beforeEach 2 end')
                success({
                    path:'/pages/login/login'
                })
            },1000)
        })
    }
})


router.afterEach((to,from)=>{
    console.log('afterEach 1 ,',to,from)
})

router.afterEach(async (to,from)=>{
    console.log('afterEach 2 begin',to,from)
    return new Promise<BeforeEachResult>((success,fail)=>{
        setTimeout(function(){
            console.log('afterEach 2 end')
            success(true)
        },1000)
    })
})

export default router
  • main.ts
import { createSSRApp } from "vue";
import router from './router'
import App from "./App.vue";

export function createApp() {
  const app = createSSRApp(App);
  app.use(router)
  return {
    app,
  };
}