GithubHelp home page GithubHelp logo

npm-react-router's Introduction

Typings-React-Router

This is typings for thee react-router

It's highly suggested to install with typings definition manager. Use the command typings install react-router --save.

You're code should look pretty much the same the javascript with one exception. When a component is used with a Route component it injects several property values. To type this the IInjectedProps interface has all the properties defined that injecting will add.

To use it extend your current Property interface with IInjectedProps.

import React from 'react';
import { render } from 'react-dom';
import { Link, Router, Route, IInjectedProps } from 'react-router';

class User extends React.Component<IInjectedProps,{}> {
  render() {
    let { userID } = this.props.params
    let { query } = this.props.location
    let age = query && query["showAge"] ? '33' : ''

    return (
      <div className="User">
        <h1>User id: {userID}</h1>
        {age}
      </div>
    )
  }
}

const HelloMessage = (props) => <div>Hello {props.params.name}</div>;

class App extends React.Component<React.Props<{}>,{}> {
  render() {
    return (
      <div>
        <ul>
          <li><Link to="/user/bob" activeClassName="active">Bob</Link></li>
          <li><Link to={{ pathname: '/user/bob', query: { showAge: true } }} activeClassName="active">Bob With Query Params</Link></li>
          <li><Link to="/user/sally" activeClassName="active">Sally</Link></li>
        </ul>
        {this.props.children}
      </div>
    )
  }
}

render((
  <Router history={browserHistory}>
    <Route path="/" component={App}>
      <Route path="user/:userID" component={User} />
      <Route path="message/:name" component={HelloMessage}/>
    </Route>
  </Router>
), document.getElementById('example'));

This is quite a large api so I might have missed some of the details. If there is something that should work or documentation that's incorrect please don't hesistate to post an issue.

npm-react-router's People

Contributors

unional avatar zaytsevvla avatar vslinko avatar malekpour avatar antonvasin avatar blakeembrey avatar palmsey avatar

Watchers

James Cloos avatar

Forkers

swipswaps

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.