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-client-router

v1.0.8

Published

基于react的客户端渲染路由

Downloads

28

Readme

1、基础使用

import React from 'react';
import { Routes, Route, OutLet} from 'react-client-router';
const isHash = true;

const Home = () => {
  return (
      <div>home <OutLet/></div>
  )
}

const Example = () => {
  return (
        <Routes hashMode={isHash}>
         <Route path="/" element={isHash ? <div>22332</div> :<Home />} />
         <Route path="/home" element={isHash ? "<div>22332</div>" :<Home />} />
          <Route path="/index" element={!isHash ? "<div>22332</div>" :<Home />}>
            <Route path={'/index/hello'} element={<div>index-page</div>} />
          </Route>
        </Routes>
  )
};
export default Example;

2、懒加载(1)

// index
import React, {lazy} from 'react';
import {Routes, Route,} from 'react-client-router';
import { Spin } from "antd";

const isHash = true;
const Home = React.lazy(() => import("./Home"));
const Main = React.lazy(() => import("./Main"));
const HomeContent = React.lazy(() => import("./HomeContent"));

const Example = () => {
  return (
      <Routes
          hashMode={isHash}
          notFound={lazy(() => import("@pages/notFound"))}
          fallback={
            <Spin
                tip="Loading"
                size="large"
                wrapperClassName={"w-h-100 relative"}
                className="w-h-100 absolute"
            >
              <div/>
            </Spin>
          }>
        <Route path="/" lazy={Home}>
          <Route path="/home/content" lazy={HomeContent} />
        </Route>
        <Route path="/main" lazy={Main} />
      </Routes>
  )
};

export default Example;


// home
import React from "react";
import {Link, OutLet} from 'react-client-router';
const Home = () => {
  return (
      <div>
        <h1>home-page</h1>
        <Link to={'/main'}>main-page</Link><br/>
        <Link to={'/home/content'}>home/content</Link><br/>
        <Link to={'/home/null'}>home/null</Link>
        <OutLet/>
      </div>
  )
}

export default Home;

// home/content

import React from "react";
import {Link} from 'react-client-router';
const HomeContent = () => {
  return (
      <div>homeContent
        <br/>
        <Link to={'/main'}>main</Link>
      </div>
  )
};

export default HomeContent;

// main

import React from "react";
import {Link} from "react-client-router";

const Main = () => {
  return (
      <div>
        <h1>main-page</h1>
        <Link to={'/home/content'}>home-page</Link>
      </div>
  )
}

export default Main;

2、懒加载(2)

import React, { lazy } from "react";
import { RoutesContainer, OutLet } from "react-client-router";
import { Spin } from "antd";
import {
  SettingOutlined,
  HomeFilled,
  DesktopOutlined,
} from "@ant-design/icons";
// import { lazyRouter } from "./utils";
// import Layout from '@pages';
export const menu = [
  {
    label: "首页",
    key: "/",
    icon: <HomeFilled />,
    path: "/",
    lazy: lazy(() => import("@pages/home")),
  },
  {
    label: "系统设置",
    key: "/setting",
    icon: <SettingOutlined />,
    path: "/setting",
    lazy: lazy(() => import("@pages/setting")),
  },
  {
    label: "前端",
    key: "/client",
    path: "/client",
    icon: <DesktopOutlined />,
    element: <OutLet />,
    children: [
      {
        label: "PDF应用",
        key: "/client/index",
        path: "/client",
        icon: <DesktopOutlined />,
        element: lazy(() => import("@pages/client/app/pdf")),
      },
    ],
  },
];
const router = [
  {
    path: "/",
    lazy: lazy(() => import("@pages")),
    children: [
      ...menu,
      {
        label: "404",
        key: "404",
        path: "/404",
        lazy: lazy(() => import("@pages/notFound")),
      },
    ],
  },
  {
    label: "登录",
    path: "/login",
    lazy: lazy(() => import("@pages/login")),
  },
];

export default () => {
  return (
    <RoutesContainer
      router={router}
      notFound={lazy(() => import("@pages/notFound"))}
      fallback={
        <Spin
          tip="Loading"
          size="large"
          wrapperClassName={"w-h-100 relative"}
          className="w-h-100 absolute"
        >
          <div/>
        </Spin>
      }
    />
  );
};