项目作者: ca-la

项目描述 :
React routing with search (AKA query) parameters.
高级语言: TypeScript
项目地址: git://github.com/ca-la/react-search-route.git
创建时间: 2019-10-02T18:20:29Z
项目社区:https://github.com/ca-la/react-search-route

开源协议:MIT License

下载


React Search Route

This library provides the ability to render children based off the existence of what resides in a querystring. Out of the box, react-router-dom does not support routing via query parameters for a plethora of reasons. So we decided to form an opinion and encapsulate querystring routing logic ourselves.

Status

Branch URL Build Status
master @cala/react-search-route"">https://www.npmjs.com/package/@cala/react-search-route CircleCI

Installation

npm install @cala/react-search-route --save

Usage

Import components individually.

  1. import SearchRoute, { SearchSwitch } from '@cala/react-search-route';

Or wrap it into a single statement.

  1. import * as ReactSearchRoute from '@cala/react-search-route';

From there, you can use <SearchSwitch ></SearchSwitch> and <SearchRoute ></SearchRoute> in effectively the same way as
<Switch ></Switch> and <Route ></Route> from react-router-dom. You’ll also need to ensure that all route
components are wrapped by a parent <BrowserRouter /> from react-router-dom.

  1. const exactMatch = (): JSX.Element => <div>Matched</div>;
  2. const noMatch = (): JSX.Element => <div>Do not match me</div>;
  3. const partialMatch = (): JSX.Element => <div>Partial match</div>;
  4. // ...
  5. <BrowserRouter>
  6. <SearchSwitch>
  7. <SearchRoute exact search={{ isFoo: 'true' }} render={exactMatch} ></SearchRoute>
  8. <SearchRoute
  9. search={{ isFoo: 'true', doesBar: 'true' }}
  10. render={partialMatch}
  11. ></SearchRoute>
  12. <SearchRoute
  13. exact
  14. search={{ isFoo: 'true', doesBar: 'true' }}
  15. render={noMatch}
  16. ></SearchRoute>
  17. </SearchSwitch>
  18. </BrowserRouter>;

For more examples, see the tests written in src/spec.tsx.

Contributing

To tag off and release a new version to npm, run the release script:

  1. $ ./bin/release patch # 0.0.x - bug fixes
  2. $ ./bin/release minor # 0.x.0 - new features or changes
  3. $ ./bin/release major # x.0.0 - large, backwards-incompatible changes