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

umi-plugin-router-plus

v1.8.1

Published

一款 Umi 3 插件,为你带来类型友好的页面参数的定义、传递与获取。

Downloads

33

Readme

umi-plugin-router-plus Node CI codecov

一款 Umi 3 插件,为你带来类型友好页面参数的定义、传递与获取


安装

# npm
npm i umi-plugin-router-plus -D

# or yarn
yarn add umi-plugin-router-plus -D

# or pnpm
pnpm add umi-plugin-router-plus -D

启用方式

默认开启。

使用介绍

定义页面参数

在页面文件内定义 Params 类型,并将之导出即可:

// src/pages/test.tsx

export interface Params {
  id: number
  enabled?: boolean
  gender: 'male' | 'female'
  name: string
  tags?: string[]
}

获取页面参数

在页面文件内定义好页面参数后,只需在页面组件内使用 usePageParams 即可获取:

// src/pages/test.tsx
import React from 'react'
import { usePageParams } from 'umi'

export interface Params {
  id: number
  enabled?: boolean
  gender: 'male' | 'female'
  name: string
  tags?: string[]
}

export default function () {
  const {
    id,
    enabled = false, // 指定默认值
    gender,
    name,
    tags = [],
  } = usePageParams('Test')

  return <div>id is: {id}</div>
}

传递页面参数

见下:API 列表

API 列表

navigateTo(pageName, params)

import { navigateTo } from 'umi'

navigateTo('Index')
navigateTo('User', { id: 2 })

保留当前页面,跳转至某个页面,和 history.push 效果一致。

redirectTo(pageName, params)

import { redirectTo } from 'umi'

redirectTo('Index')
redirectTo('User', { id: 2 })

关闭当前页面,跳转至某个页面,和 history.replace 效果一致。

navigateBack(delta)

import { navigateBack } from 'umi'

navigateBack()
navigateBack(2)

关闭当前页面,返回上一页面或多级页面,和 history.goBack 效果一致。

navigateForward(delta)

import { navigateForward } from 'umi'

navigateForward()
navigateForward(2)

保留当前页面,前进到下一页面或多级页面,和 history.goForward 效果一致。

usePageName()

import { usePageName } from 'umi'

const pageName = usePageName()

获取当前页面的名称。

usePageParams(pageName)

import { usePageParams } from 'umi'

const { id } = usePageParams('User')

获取传给页面的参数,会继承所有父 layout 页面定义的参数

usePageQuery()

import { usePageQuery } from 'umi'

const { source } = usePageQuery<{
  source: string
}>()

获取传给页面的 query。

useQuery()

usePageQuery,不再推荐使用,未来版本会被移除。

页面名称

页面名称会根据路由的 path 自动生成,如果程序没有提示你页面名称重复,大可不必深究。

比如,页面路径 /user/detail 生成的页面名称为 UserDetail

许可

Jay Fong (c) MIT