react-router-lite

Similar to `react-router` but leaner.

Unlicense 8 个版本
安装
npm install react-router-lite
yarn add react-router-lite
pnpm add react-router-lite
bun add react-router-lite
README

react-router-lite

Similar to react-router but leaner.

Provide your route in the [route] prop to the Router component and use the Route components to define your routes.

import {Router, Route} from 'react-router-lite';

<Router route="/foo/bar">
   <Route>
      <span>1</span>
   </Route>
   <Route match="/baz">
      <span>2</span>
   </Route>
   <Route match="/foo">
      <span>3</span>
   </Route>
   <Route match="/foo/bar">
      <span>4</span>
   </Route>
</Router>;

You can use the Switch component to render only the first route that matches.

import {Router, Switch, Route} from 'react-router-lite';

<Router route={'/any/string/goes/here'}>
   <Switch>
      <Route match="/any/string" render={() => <div>hello world</div>}>
      <Route match="/any/string/goes" render={() => <div>not hello</div>}>
   </Switch>
</Router>

The routes can be nested. When [truncate] prop is set, the nested routes will be truncated to the parent route.

import {Router, Route} from 'react-router-lite';

<Router route="/foo/bar">
   <Route match={'/foo'} truncate>
      <span>foo</span>
      <Route match="/bar">
         <span>bar</span>
      </Route>
   </Route>
</Router>;

License

Unlicense — public domain.

版本列表
1.6.0 2024-05-20
1.5.0 2024-05-18
1.4.0 2022-04-02
1.3.0 2020-05-29
1.2.0 2020-05-07
1.1.1 2019-04-09
1.1.0 2019-04-09
1.0.0 2019-04-08