hotfix: pass location down in sidebar

This commit is contained in:
George Lima 2018-12-11 21:15:38 -03:00
parent efe32a5227
commit a39dd135f6
3 changed files with 9 additions and 11 deletions

View File

@ -13,7 +13,7 @@ describe('<Sidebar />', () => {
// $FlowFixMe
const { asFragment } = render(
<MemoryRouter>
<SidebarComponent />
<SidebarComponent location={{ pathname: '/', hash: '/', search: '' }} />
</MemoryRouter>,
);

View File

@ -2,7 +2,7 @@
import React, { type Element } from 'react';
import styled from 'styled-components';
import { Link, withRouter, type Match } from 'react-router-dom';
import { Link, type Location } from 'react-router-dom';
import { MENU_OPTIONS } from '../constants/sidebar';
import { ZCashLogo } from './zcash-logo';
@ -48,16 +48,16 @@ type MenuItem = {
type Props = {
options?: MenuItem[],
match: Match,
location: Location,
};
const Sidebar = ({ options, match }: Props) => (
export const SidebarComponent = ({ options, location }: Props) => (
<Wrapper>
<LogoWrapper>
<ZCashLogo />
</LogoWrapper>
{(options || []).map(item => (
<StyledLink isActive={match.path === item.route} key={item.route} to={item.route}>
<StyledLink isActive={location.pathname === item.route} key={item.route} to={item.route}>
{React.cloneElement(item.icon, {
style: { marginRight: '15px' },
size: 20,
@ -68,8 +68,6 @@ const Sidebar = ({ options, match }: Props) => (
</Wrapper>
);
export const SidebarComponent = withRouter(Sidebar);
Sidebar.defaultProps = {
SidebarComponent.defaultProps = {
options: MENU_OPTIONS,
};

View File

@ -1,7 +1,7 @@
// @flow
import React from 'react';
import { Route, Switch } from 'react-router-dom';
import { Route, Switch, type Location } from 'react-router-dom';
import styled from 'styled-components';
import { ScrollTopComponent } from './scroll-top';
@ -24,9 +24,9 @@ const Wrapper = styled.div`
width: 100vw;
`;
export const RouterComponent = () => (
export const RouterComponent = ({ location }: { location: Location }) => (
<Wrapper>
<SidebarContainer />
<SidebarContainer location={location} />
<ScrollTopComponent>
{/* $FlowFixMe */}
<LayoutComponent>