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

vser-router

v1.0.4

Published

router for vser , integrated with vser for spa

Readme

vser-router

1、vser的路由插件,用于实现单页应用;

2、支持hash和history模式;

3、支持路由缓存;

4、支持路由嵌套,如:

  `<Page>
    <Header slot="header">
        <div style="color:#fff;" slot="left">我才是左侧按钮</div>
    </Header>
    <RouterView></RouterView>
    <Footer slot="footer"></Footer>
</Page>`  

5、用法:

import VserRouter from 'vser-router';
import Vser from 'vser';

Vser.use(VserRouter);
const router = new VserRouter({
    mode: 'hash', //模式:hash|history
    routes: [], //路由配置
    default: '',//默认路由
    base: '',//路由前缀
    pathChange: function (path) {},
    before: function (route, prev) {}, //路由即将进入
    ready: function (route) {}, //路由加载就绪
    fail: function (route) {}, //路由加载失败
    after: function (route, next) {}, //路由即将离开
    notFound: function (path) {
        console.error(`${path} 当前路由没找到`)
    }, //路由未找到
    routes: []
});

new xxx({
    el: document.getElementById('app'),
    router,
});

初始化成功后,任何组件都可以通过this.$router访问路由对象实例,调用路由方法;
通过this.$router.route 获取当前页面路由信息和参数;

6、路径配置,如:

[{
        path: '/home',   
        name: 'home',   
        cache: false,   
        meta: {         
            title: '测试'   
        },
        component: resolve => require(['./_components/main/index'], resolve), 
        children: [{
                path: 'second/:id',
                name: 'second',
                component: resolve => require(['./_components/second/'], resolve)
            },
            {
                path: ':id/third',
                name: 'third',
                component: resolve => require(['./_components/third/'], resolve)
            },

        ]
    },
];

参数解释:

path: 路由路径,支持动态参数。
       参数以冒号开头如: path: 'second/:id/xxx/:xxx/'

name: 路由名

cache: 是否缓存(boolean),若为true:路由离开时,组件会被缓存,再次进入时,会自动从缓存恢复。

meta:  有关页面信息

component: 路由组件,可同步引入,也可异步引入
           同步引入示例:  component: require('./_components/second/')
           异步引入示例:  component: resolve => require(['./_components/second/'], resolve)

children: 子路由配置(array)

7、路由跳转

通过调用路由实例的跳转方法来实现跳转,跳转方法如下:


 /**
 * 路由跳转,可通过name名称跳转,也可通过path跳转
 * @param {Object} option 
 * @param {String} option.name   路由名
 * @param {String} option.path   路由路径(优先级高于路由名)
 * @param {Object} option.params 路由参数(路径动态参数在此设置)
 */
push(option)


/**
 * 路由跳转 replace模式,可通过name名称跳转,也可通过path跳转
 * @param {Object} option 
 * @param {String} option.name   路由名
 * @param {String} option.path   路由路径(优先级高于路由名)
 * @param {Object} option.params 路由参数(路径动态参数在此设置)
 */
replace(option)


/**
 * 路由跳转
 * @param {number} n 前进或后退n步(后退请设置负数) 
 */
go(n)