Skip to content

Commit

Permalink
make components "active" using appropriate props
Browse files Browse the repository at this point in the history
No need for ternaries, you can use the props "activeClassName" and "onlyActiveOnIndex" which will work accordingly.

Source: https://github.com/reactjs/react-router-tutorial/tree/master/lessons/09-index-links

(I know this probably won't get committed, b/c then you'd have to do a whole new video. However, if you do commit, you could comment out the old version so that people won't be completely lost when they DL the source code.)
  • Loading branch information
gfantom committed Jul 6, 2016
1 parent 16fb07d commit 2cf5e56
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions 2-react-router/src/js/components/layout/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export default class Nav extends React.Component {
render() {
const { location } = this.props;
const { collapsed } = this.state;
const featuredClass = location.pathname === "/" ? "active" : "";
const archivesClass = location.pathname.match(/^\/archives/) ? "active" : "";
const settingsClass = location.pathname.match(/^\/settings/) ? "active" : "";
// const featuredClass = location.pathname === "/" ? "active" : "";
// const archivesClass = location.pathname.match(/^\/archives/) ? "active" : "";
// const settingsClass = location.pathname.match(/^\/settings/) ? "active" : "";
const navClass = collapsed ? "collapse" : "";

return (
Expand All @@ -35,13 +35,13 @@ export default class Nav extends React.Component {
</div>
<div class={"navbar-collapse " + navClass} id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class={featuredClass}>
<li activeClassName="active" onlyActiveOnIndex={true}>
<IndexLink to="/" onClick={this.toggleCollapse.bind(this)}>Featured</IndexLink>
</li>
<li class={archivesClass}>
<li activeClassName="active">
<Link to="archives" onClick={this.toggleCollapse.bind(this)}>Archives</Link>
</li>
<li class={settingsClass}>
<li activeClassName="active">
<Link to="settings" onClick={this.toggleCollapse.bind(this)}>Settings</Link>
</li>
</ul>
Expand Down

3 comments on commit 2cf5e56

@dgdosen
Copy link

@dgdosen dgdosen commented on 2cf5e56 Jan 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change doesn't work for me... I need to revert to get the active tab settings to work properly....

@slavovthinks
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not work for me as well...

@sethillgard
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1. Does not work.

Please sign in to comment.