hookrouter

The flexible, and fast router for react that is entirely based on hooks

Github星跟蹤圖

React Hook Router

The modern alternative to react-router.

Tested from React 16.8.1 upwards.

How to install

Well, this is straightforward:

npm i hookrouter

Typescript

This project is not and will not be written in typescript.

Thanks to the github user @mcaneris, you can install types via:

npm i @types/hookrouter

I did not check if those types are correct nor will I keep them up to date with future releases.

Documentation

Detailed documentation about how to use hookrouter can be found here

A quick example

import {useRoutes} from 'hookrouter';

const routes = {
    '/': () => <HomePage />,
    '/about': () => <AboutPage />,
    '/products': () => <ProductOverview />,
    '/products/:id': ({id}) => <ProductDetails id={id} />
};
	
const MyApp = () => {
    const routeResult = useRoutes(routes);
    
    return routeResult, <NotFoundPage />;
}

Routes are defined as an object. Keys are the routes, which are matched
against the URL, the values need to be functions that are called when a route
matches. You may define placeholders in your routes with :something which
will be forwarded as props to your function calls so you can distribute them
to your components.

The hook will return whatever the route function returned, so you may also return
strings, arrays, React fragments, null - whatever you like.

主要指標

概覽
名稱與所有者Paratron/hookrouter
主編程語言JavaScript
編程語言JavaScript (語言數: 2)
平台
許可證
所有者活动
創建於2019-02-12 23:45:15
推送於2022-09-14 03:13:10
最后一次提交2020-12-01 15:23:57
發布數6
最新版本名稱1.2.5 (發布於 )
第一版名稱v1.1.7 (發布於 2019-04-26 23:36:14)
用户参与
星數1.5k
關注者數21
派生數88
提交數138
已啟用問題?
問題數137
打開的問題數59
拉請求數10
打開的拉請求數5
關閉的拉請求數17
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?