Skip to content

Commit 44eadea

Browse files
committed
navigation - Fix active check
Earlier it could match too much (i.e. /concepts/configuration highlighted both concepts and configuration). I also dropped dependency on `window`. As a side benefit navigation highlight works in development mode now as well.
1 parent 1e06c5b commit 44eadea

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

components/navigation/navigation.jsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ import './navigation-style';
66

77
export default class Navigation extends React.Component {
88
render() {
9-
let pathname = '';
10-
let isIndex = false;
11-
12-
if (typeof window !== 'undefined') {
13-
pathname = window.location.pathname;
14-
isIndex = pathname === '' || pathname === '/';
15-
}
9+
const { pageUrl, sections } = this.props;
1610

1711
return (
1812
<header className="navigation">
@@ -27,8 +21,8 @@ export default class Navigation extends React.Component {
2721

2822
<nav className="navigation__links">
2923
{
30-
this.props.sections.filter(section => section.title !== 'Other').map((link, i) => {
31-
let active = pathname === `/${link.url}` || pathname.includes(`/${link.url}/`);
24+
sections.filter(section => section.title !== 'Other').map((link, i) => {
25+
let active = pageUrl.includes(`${link.url}/`);
3226
let activeClass = active ? 'navigation__link--active' : '';
3327

3428
return (

components/site/site.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export default props => {
3030
<Interactive
3131
id="components/navigation/navigation.jsx"
3232
component={ Navigation }
33-
sections={ sections } />
33+
sections={ sections }
34+
pageUrl={ props.children.props.page.url } />
3435

3536
<Interactive
3637
id="components/sidebar-mobile/sidebar-mobile.jsx"

0 commit comments

Comments
 (0)