Skip to content

simon-rad/react-router-props

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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);

About

React router shape and location shape for react-router props

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •