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

vue-router-tools

v1.0.28

Published

An enhanced toolset for vue router

Downloads

39

Readme

Essentials:

1. init-router

Features:

1.Injected router instances into the global routing guard, where 'this' can be used

2.Redefining the replace and push methods to eliminate asynchronous error reporting by routing guards

3.Delayed call to global routing guards, such as when using pinia in the guard, an error will be reported. This attribute can be used to fix this. If there is an infinite loop when resetting the dynamic route(use addRoute), please turn off this option

// router/index.js

import initRouter from 'vue-router-tools/init-router';
import routes from './routes';
import beforeEach from './before-each';
import afterEach from './after-each';

export default initRouter({ routes, beforeEach, afterEach });
// main.js

import router from './router/index';

new Vue({
  render: (h) => h(App),
  router
}).$mount('#app');

| | desc | default | explain | | ---------- | ----------------------------------------------------------------------------------------------- | ----------------------------- | ----------------------------------------------------------------------------------- | | beforeEach | navigation guards | function (to,from,next) {...} | 'this' point to router instances in guard is available when not use arrow functions | | afterEach | navigation guards | function (to,from,next) {...} | ditto | | lazyHooks | delay call the route guard | false | | | ...others | vue-router-example | | |

2. add-route

// router/before-each.js

import addRoute from 'vue-router-tools/add-route';

const parentName = 'admin';
let isRouteAdded = false;

export default async function (to, from, next) {
  if (!isRouteAdded) {
    // replace your own dynamic-routes request here
    const routes = await fetch('/get-menu');
    const { replaceTo } = addRoute({
      to,
      routes,
      router: this, // if not use init-router and use arrow function,then the "this" is "undifined",or replace the router instance here
      parentName
    });
    isRouteAdded = true;
    replaceTo();
  } else {
    next();
  }
}

props:

| | desc | type | | ---------- | ------------------------------------------------------------------------------------------------- | ----------------- | | routes | the dynamic routes from request | Array | | router | the Router's instance | Router's instance | | parentName | the parentName of dynamic-routes | String | | to | the navigation guard's "to" | Object | | notFound | the RouteConfig of notFound | Object |

return value:

| | desc | type | | ----------- | --------------------------------------- | -------- | | replaceTo | for dynamic route first time navigation | Function | | resetRouter | reset the dynamic routes | Function |

3.bread-crumbs

Auto generate dynamic bread crumbs based on vue router

Note:

The route corresponding to each breadcrumb needs to configure the meta attribute, and configure the display text of the route in it

Usage:

import Vue from 'vue';
import Router from 'vue-router';
import autoCrumbs from 'vue-router-tools/bread-crumbs';

Vue.use(Router);
const router = new Router({...})

router.beforeEach((to,from,next)=>{
    const { matched } = to;
  /**
   * @first       --   When there is a homepage, put it at the first of the breadcrumbs
   * @metaNameKey --   Custom your meta name field, the 'name' is default
   */
  const crumbs = autoCrumbs({ matched, first: {text:'',to:''}, metaNameKey:''});
  // The value obtained here should be saved in store (vuex or pinia).
  console.log(crumbs);
    // ...
  next()
})