Created
March 4, 2016 21:37
-
-
Save tdurand/fafa4020aede5ca6fd53 to your computer and use it in GitHub Desktop.
Active Link Unexpected behaviour with query param React Router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { render } from 'react-dom' | |
import { Router, Route, IndexRoute, Link, IndexLink, browserHistory } from 'react-router' | |
const ACTIVE = { color: 'red' } | |
class App extends React.Component { | |
render() { | |
return ( | |
<div> | |
<h1>APP!</h1> | |
<ul> | |
<li><IndexLink to="/users" activeStyle={ACTIVE}>/users IndexLink</IndexLink></li> | |
<li><Link to={{ pathname: '/users', query: { type: 'test' } }} activeStyle={ACTIVE}>/users&type=test Link</Link></li> | |
</ul> | |
{this.props.children} | |
</div> | |
) | |
} | |
} | |
class Index extends React.Component { | |
render() { | |
return ( | |
<div> | |
<h2>Index!</h2> | |
</div> | |
) | |
} | |
} | |
class Users extends React.Component { | |
render() { | |
return ( | |
<div> | |
<h2>Users</h2> | |
{this.props.children} | |
</div> | |
) | |
} | |
} | |
class UsersIndex extends React.Component { | |
render() { | |
return ( | |
<div> | |
<h3>UsersIndex</h3> | |
</div> | |
) | |
} | |
} | |
class User extends React.Component { | |
render() { | |
return ( | |
<div> | |
<h3>User {this.props.params.id}</h3> | |
</div> | |
) | |
} | |
} | |
class About extends React.Component { | |
render() { | |
return ( | |
<div> | |
<h2>About</h2> | |
</div> | |
) | |
} | |
} | |
render(( | |
<Router history={browserHistory}> | |
<Route path="/" component={App}> | |
<IndexRoute component={Index}/> | |
<Route path="/about" component={About}/> | |
<Route path="users" component={Users}> | |
<IndexRoute component={UsersIndex}/> | |
<Route path=":id" component={User}/> | |
</Route> | |
</Route> | |
</Router> | |
), document.getElementById('example')) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment