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

react-router6-prompt

v1.1.0

Published

为react-router6附加prompt功能

Downloads

22

Readme

react-router6-prompt

由于目前react-router6中仍未支持 Prompt,但是在有些时候不得不使用此功能,所以此模块,仅实现此功能仅此而已。

安装

npm install react-router6-prompt

使用

首先导入Router,包括 BrowserRouterHashRouter 两种模式。

import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
// 使用HashRouter,同样的方法导入即可
import {BrowserRouter} from 'react-router-prompt';

ReactDOM.render(
  <React.StrictMode>
    <HashRouter>
      <App />
    </HashRouter>
  </React.StrictMode>,
  document.getElementById('root')
)

在需要使用Prompt功能的页面内添加

import React from 'react';
import {browserHistory, Prompt} from 'react-router6-prompt';
// 如果使用的是HashRouter,这里引入hashHistory即可。

const Page = () => {
    return (
        <>
            <Prompt history={browserHistory} when={true} message={() => {
                return true;
            }}>
        </Prompt>
    );
}

export default Page;

关于Prompt组件

在使用 Prompt 组件时,该组件有三个prop参数:

  • history ,支持 browserHistoryhashHistory
  • when ,boolean,设置是否开启页面切换或卸载效验。
  • messagestring() => boolean() => Promise<boolean> 支持三种类型,使用 string 作为参数则使用浏览器默认的 confirm 作为页面切换或卸载时的确认控件,使用后面两种则可以自定义切换或卸载时的控件控件。