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

@kkt/plugin-pro-router

v1.1.5

Published

kktp plugins

Downloads

107

Readme

路由配置

kktp内置插件,用于自动进行生成路由配置。使用此插件需要安装react-routerreact-router-dom依赖包

参数

export interface RouterPluginProps {
  /**处理图标菜单中图标引入问题*/
  analysisRoutersIcon?: (icons: { name: string; newName: string }[]) => string;
  /**
   * @description 在src目录下生成的临时文件夹名称
   * @default .kktp
   * */
  cacheDirName?: string;
  /**
   * @description 路由类型
   * @default "hash"
   */
  routesType?: 'browser' | 'hash' | 'memory';
  /** 路由权限名称,默认查找src目录下access.[js | ts]文件 */
  accessDirName?: string;
  /**页面加载loading组件地址*/
  fallbackElement?: string;
  /**路由外层包裹组件,可以用于自定义添加路由**/
  routesOutletElement?: string;
  /**自动生成路由配置*/
  autoRoutes?: boolean;
  /**自动生成路由layout布局组件地址*/
  outletLayout?: string;
}

路由生成方式

1. 通过配置进行生成路由

2. 自动生成路由

  • 约定src/pages文件夹为根据生成路由
  • 约定src/pages/index.(js|jsx|tsx)文件为默认路由
  • 约定src/pages/**/index.(js|jsx|tsx)文件为对应路由展示页面

页面参数

kktp中,页面内置了rolesnavigateroutes

  • roles 页面权限,config/routes.json菜单上配置了 roles,则在页面上获取。

  • navigate 跳转。

  • routes 路由path="/"路由下的子集路由集合。

import { KktproPageProps } from '@kkt/pro';

const Page = (props: KktproPageProps) => {
  const { navigate, roles = [], routes = [] } = props;

  return <div />
};
export default Page;

页面跳转

页面中可直接通过 navigate 跳转, 或者通过react-router-dom提供的 useNavigate来跳转。

import { KktproPageProps, useNavigate } from '@kkt/pro';

const Page = (props: KktproPageProps) => {
  const { navigate } = props;
  // const navigate = useNavigate();

  const click = () => {
    navigate('/demo');
  };

  return <button onClick={click}>navigate</button>
};
export default Page;

支持页面导出react-router 6配置参数

// 路由加载文件 src/pages/about/index.tsx
const Index = ()=>{
  return <div>导出element</div>
}
export default Index;
export const element = <Index />;
export const loader = ()=>{}
export const action = ()=>{}
const ErrorElement = ()=><div>errorElement</div>
export const errorElement =<ErrorElement />
export const lazy=()=>import("@/about")
export const path="/about"
export const shouldRevalidate=({ currentUrl }) => {
  // only revalidate if the submission originates from
  // the `/meal-plans/new` route.
  return currentUrl.pathname === "/meal-plans/new";
}

kktp配置文件

// .kktprc.ts
export default {
  // ...
  initRoutes:{
    outletLayout:"@/layout" // 自动生成路由layout布局组件地址
  },
}

Contributors

License

Licensed under the MIT License.