Commit fc8197b4 by zhanghaozhe

nav icon

parent 14f6bd88
import React from 'react'; import React from 'react';
import { NavLink } from 'react-router-dom' import { NavLink, withRouter } from 'react-router-dom'
import './index.scss'; import './index.scss';
const navLinkConfig = [ const navLinkConfig = [
...@@ -7,29 +7,33 @@ const navLinkConfig = [ ...@@ -7,29 +7,33 @@ const navLinkConfig = [
to: '/', to: '/',
exact: true, exact: true,
icon: 'iconshouye-xianxing', icon: 'iconshouye-xianxing',
activeIcon: 'iconshouye1',
text: '首页' text: '首页'
}, },
{ {
to: '/classify', to: '/classify',
exact: false, exact: false,
icon: 'iconfenlei-xianxing', icon: 'iconfenlei-xianxing',
activeIcon: 'iconfenlei-chunse',
text: '分类' text: '分类'
}, },
{ {
to: '/study', to: '/study',
exact: false, exact: false,
icon: 'iconxuexi-xianxing', icon: 'iconxuexi-xianxing',
activeIcon: 'iconxuexi-chunse',
text: '学习' text: '学习'
}, },
{ {
to: '/my', to: '/my',
exact: false, exact: false,
icon: 'iconwode-xianxing', icon: 'iconwode-xianxing',
activeIcon: 'iconwode-chunse',
text: '我的' text: '我的'
} }
] ]
const NavBar = React.memo(() => { const NavBar = React.memo(({location}) => {
return ( return (
<div className="nav-bar"> <div className="nav-bar">
{ {
...@@ -42,7 +46,7 @@ const NavBar = React.memo(() => { ...@@ -42,7 +46,7 @@ const NavBar = React.memo(() => {
key={icon} key={icon}
{...rest} {...rest}
> >
<i className={`iconfont ${icon}`}/> <i className={`iconfont ${location.pathname.startsWith(item.to) ? item.activeIcon : item.icon}`}/>
<span>{text}</span> <span>{text}</span>
</NavLink> </NavLink>
) )
...@@ -52,4 +56,4 @@ const NavBar = React.memo(() => { ...@@ -52,4 +56,4 @@ const NavBar = React.memo(() => {
) )
}) })
export default NavBar export default withRouter(NavBar)
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment