Skip to content

Commit e29afdd

Browse files
committed
docs: hopefully fix active nav link style
1 parent 225a555 commit e29afdd

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

www/src/components/Layout.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { graphql, Link } from 'gatsby';
1+
import { graphql, Link, withPrefix } from 'gatsby';
22
import PropTypes from 'prop-types';
33
import React from 'react';
44

@@ -25,22 +25,40 @@ const propTypes = {
2525
}).isRequired,
2626
};
2727

28-
const NavItem = ({ active, to, children }) => (
29-
<li role="presentation" className={active ? 'active' : null}>
30-
<Link aria-selected={active} to={to}>
28+
const NavItem = ({ to, location, children }) => (
29+
<li role="presentation">
30+
<Link
31+
to={to}
32+
location={location}
33+
activeStyle={{
34+
color: '#fff',
35+
backgroundColor: '#080808',
36+
}}
37+
>
3138
{children}
3239
</Link>
3340
</li>
3441
);
3542

3643
NavItem.propTypes = {
37-
active: PropTypes.bool,
3844
to: PropTypes.string.isRequired,
45+
location: PropTypes.shape({
46+
pathname: PropTypes.string.isRequired,
47+
}).isRequired,
48+
children: PropTypes.node.isRequired,
3949
};
4050

4151
class Layout extends React.Component {
52+
isActive(path, location) {
53+
return withPrefix(path) === withPrefix(location.pathname);
54+
}
55+
4256
render() {
43-
const { data, location, children } = this.props;
57+
const { data, children } = this.props;
58+
const location = {
59+
...this.props.location,
60+
pathname: withPrefix(this.props.location.pathname),
61+
};
4462
return (
4563
<div>
4664
<Navbar fixedTop inverse collapseOnSelect>
@@ -54,11 +72,7 @@ class Layout extends React.Component {
5472
<Nav pullRight>
5573
{data.site.siteMetadata.componentPages.map(
5674
({ path, displayName }) => (
57-
<NavItem
58-
key={path}
59-
active={path === location.pathname}
60-
to={path}
61-
>
75+
<NavItem key={path} to={path} location={location}>
6276
{displayName}
6377
</NavItem>
6478
)

0 commit comments

Comments
 (0)