react-router-props

1.0.2 • Public • Published

react-router-props

React router prop-types. Shapes for location, history and match, they are provided with withRouter enhancer.

Usage example

import React from 'react';
import { withRouter } from 'react-router';
import { locationShape, historyShape, matchShape } from 'react-router-props';

class UsersScreen extends React.Component {

  static propTypes = {
    location: locationShape.isRequired,
    history: historyShape.isRequired,
    match: matchShape.isRequired,
  };

  componentDidMount() {
    console.log(this.props.location.pathname);
    console.log(this.props.match.isExact);
  }

  handleClick = () => this.props.history.push('/');

  render() {
    return <button onClick={this.handleClick} >User</button>;
  }
}

export default withRouter(UsersScreen);

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.2
    221
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.2
    221
  • 1.0.1
    2
  • 1.0.0
    1

Package Sidebar

Install

npm i react-router-props

Weekly Downloads

192

Version

1.0.2

License

ISC

Last publish

Collaborators

  • s.radionov