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

with-enhance-router

v0.0.3

Published

增强 with-router

Readme

with-enhance-router

增强 with-router

NPM JavaScript Style Guide

Install

npm install --save with-enhance-router

插件作用:

跨页面传参

使用方法:

引入此装饰器后, 可以直接点击调转跳转到新页面进行跨页面传参


import withEnhanceRouter from 'with-enhance-router';

export const routeNames = {
  MAIN: '/',
  LOGIN: '/login',
  KOL: '/kol',
  AUTH: '/auth',
  AWARD: '/award/:noKolModal/:id/:text',
  FRIEND: '/friend'
}

@withEnhanceRouter
export default class Main extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      loginStatus: {
        account: '',
        authenticated: false,
        modal: null
      }
    };
  }

  componentDidMount() {
    console.log(this.props);
  }

  handleClick = () => {
    const { $router } = this.props;
    $router.push({
      url: routeNames.AWARD,
      params: {
        id: 123
      },
      qs: {
        aa: '123'
      }
    });
  };

  render() {
    return (
      <MobileLayout>
        <div className={styles.main}>
          <div onClick={this.handleClick}>点击按钮</div>
        </div>
      </MobileLayout>
    );
  }
}

传参用法如下:

  1. 在页面中最顶层设置好各个路由地址
/*路由地址*/
export const routeNames = {
  MAIN: '/',
  LOGIN: '/login',
  KOL: '/kol',
  AUTH: '/auth',
  AWARD: '/award/:noKolModal/:id/:text',
  FRIEND: '/friend'
}

一、不带参数跳转使用方法, 即直接传入 url 地址:

const { $router } = this.props;
 handleClick = () => {
    this.props.$router.push(routeNames.MAIN);  
 }


 handleClick = () => {
   $router.push({
       url: routeNames.MAIN,
       params: {
           id: 123
       }
   });  
 }
 
handleClick = () => {
   $router.push({
       url: routeNames.MAIN,
       qs: {
           aa: '123'
       }
   }); 
 }
 
 handleClick = () => {
    $router.push({
        url: routeNames.MAIN,
        params: {
            id: 123
        }, qs: {
            aa: '123'
        }
    }); 
  }

获取跨页面传参的值(直接打印获取 this.props.$router 的值)

  componentDidMount() {
    console.log(this.props.$router);
  }

按实际需求,可以直接穿地 进行 params (类似于:routeNames.AWARD ) 或 querystring 传参('./index.html?aa=123')

  • $router.push(routeNames.MAIN);
  • $router.push({url: routeNames.MAIN, params});
  • $router.push({url: routeNames.MAIN, params: {id:123}, qs: {aa: '123'}});
  • $router.replace(routeNames.MAIN);
  • $router.replace({url: routeNames.MAIN, params});
  • $router.replace({url: routeNames.MAIN, params: {id:123}, qs: {aa: '123'}});
  • $router.go(<前进或后退>);

License

MIT © x13524

author: x13524