【发布时间】:2017-09-06 12:37:50
【问题描述】:
我正在使用 react-router-dom,当 url 匹配时我需要将链接设为红色,在我的 up 中有两个 url / => home 和 /map。
使用当前代码,我可以路由到不同的页面,但是在浏览器中更改 url 时,NavLink 没有突出显示。任何想法如何解决它。
import React from 'react'
import { NavLink, Route } from 'react-router-dom'
const Navigation = ({ onClick, id, title, tooltip, url }) => {
return (
<div onClick={onClick} alt={tooltip}>
{ <Route path={url} exact children={({ match }) => (
<div style={match ? {color: 'red'} : {}}>
{match ? '> ' : ''}<NavLink to={url}>{title}</NavLink>
</div>
)} />}
</div >
)
}
export default Navigation
const Root = ({ store }) => (
<Provider store={store}>
<Router>
<Switch>
<Route exact path='/' component={Forecast} />
<Route exact path='/map' component={Map} />
</Switch>
</Router>
</Provider>
)
【问题讨论】:
-
是的,正确,我想将映射 URL 的链接标记为活动。谢谢
标签: javascript reactjs react-router