Code Monkey home page Code Monkey logo

react-search-route's Introduction

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 https://www.npmjs.com/package/@cala/react-search-route CircleCI

Installation

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

Usage

Import components individually.

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

Or wrap it into a single statement.

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

From there, you can use <SearchSwitch /> and <SearchRoute /> in effectively the same way as <Switch /> and <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.

const exactMatch = (): JSX.Element => <div>Matched</div>;
const noMatch = (): JSX.Element => <div>Do not match me</div>;
const partialMatch = (): JSX.Element => <div>Partial match</div>;

// ...

<BrowserRouter>
  <SearchSwitch>
    <SearchRoute exact search={{ isFoo: 'true' }} render={exactMatch} />
    <SearchRoute
      search={{ isFoo: 'true', doesBar: 'true' }}
      render={partialMatch}
    />
    <SearchRoute
      exact
      search={{ isFoo: 'true', doesBar: 'true' }}
      render={noMatch}
    />
  </SearchSwitch>
</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:

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

react-search-route's People

Contributors

alekhinen avatar alevkon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.