09-react-router

中文文档
0.0.4发布于 2023/08/06MITES Module

This npm package provides a custom version of the Router, Route, and Link components for React. These components are designed to be lightweight, flexible, and easy to use, allowing you to handle client-side routing in your React applications efficiently.

原始使用文档
文档目录7 节
  1. Installation
  2. Usage
  3. Components
  4. Router
  5. Route
  6. Link
  7. Contributing

09 REACT ROUTER

This npm package provides a custom version of the Router, Route, and Link components for React. These components are designed to be lightweight, flexible, and easy to use, allowing you to handle client-side routing in your React applications efficiently.

Installation

You can install the package using npm or yarn:

npm i 09-react-router

# or

yarn i 09-react-router

Usage

To use React Router components, follow these steps:

  1. Import the components:
import { Router, Route, Link } from '09-react-router'
  1. Set up your routing in your applicaction:

export function App() {
    return (
    <Router>
      <Route
        path="/"
        Component={() => {
          return (
            <>
              <h1>Home</h1>
              <nav>
                <ul>
                  <li>
                    <Link to="/">Home</Link>
                  </li>
                  <li>
                    <Link to="/about">About</Link>
                  </li>
                  <li>
                    <Link to="/contact">Contact</Link>
                  </li>
                </ul>
              </nav>
            </>
          );
        }}
      />
      <Route
        path="/about"
        Component={() => {
          return (
            <>
              <h1>About</h1>
              <nav>
                <ul>
                  <li>
                    <Link to="/">Home</Link>
                  </li>
                  <li>
                    <Link to="/about">About</Link>
                  </li>
                  <li>
                    <Link to="/contact">Contact</Link>
                  </li>
                </ul>
              </nav>
            </>
          );
        }}
      />
      <Route
        path="/contact"
        Component={() => {
          return (
            <>
              <h1>Contact</h1>
              <nav>
                <ul>
                  <li>
                    <Link to="/">Home</Link>
                  </li>
                  <li>
                    <Link to="/about">About</Link>
                  </li>
                  <li>
                    <Link to="/contact">Contact</Link>
                  </li>
                </ul>
              </nav>
            </>
          );
        }}
      />
    </Router>
    )
}
  1. Define your route components:
export const Home = () => <h2>Home</h2>
export const About = () => <h2>About</h2>
export const Contact = () => <h2>Contact</h2>

Components

Router

The Router component is the top-level component that holds the routing configuration and renders the appropriate Route component based on the current URL.

Props:

routes: (Optional) Array with optional routes instead of Route component. Example:

const routes = [
    {
     path: '/',
     Component: () => <h1>Home</h1>
    },
    {
     path: '/about',
     Component: () => <h1>About</h1>
    }
]

defaultComponent: (Optional) Default component to render if any routes or children in Router is founded.

Route

The Route component is used to define a route and render the corresponding component when the URL matches the specified path.

Props:

path (string): The URL path for the route. component (function): The React component to render when the URL matches the path.

The Link component is used to create links to navigate between different routes.

Props:

to (string): The URL path to navigate to when the link is clicked.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open a new issue or submit a pull request.

This is just an npm package to recreate a own router for educational purposes only.

版本与发布记录

09-react-router 共发布 4 个版本,首次发布于 2023/08/06;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.0.4latest2023/08/063 年前
0.0.32023/08/063 年前
0.0.22023/08/063 年前
0.0.12023/08/063 年前

关于 09-react-router 的常见问题

09-react-router 是什么?

这个npm包为React提供了自定义版本的Router、Route和Link组件。这些组件被设计为轻量级、灵活且易于使用,允许您在React应用程序中有效地处理客户端路由。

如何安装 09-react-router?

在项目目录运行 npm install 09-react-router,或使用 pnpm add / yarn add / bun add。

09-react-router 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/09-react-router 是否存在。

09-react-router 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

09-react-router 可以商用吗?

09-react-router 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

09-react-router 还在维护吗?

最新版本 0.0.4 发布于 2023/08/06(3 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/08/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。