可以给link设置activeClassName;但是当有二级页面的时候一级页面的claa就失效了 ;
我的给导航 /index设置了
在/index/a的时候activeClassName 失效了
是否 /index/a链接的时候就不用link了 就直接用a就可以了
关于react-route中link
MrLhx
#1
MrLhx
#4
<IndexLink to={e.url} activeClassName="active">{e.name}</IndexLink>
<Link to={e.url} activeClassName="active">{e.name}</Link>
MrLhx
#7
<IndexLink to="/" activeClassName="active">index</IndexLink>
<Link to='/a' activeClassName="active">aa</Link>
<Link to='/a/a' activeClassName="active">aa>a</Link>
当我在/a的时候/a被激活
但是我在/a/a的时候我也想/a激活,现在是/a不会被激活了
MrLhx
#9
<Router history={hashHistory}>
<Route path="/" component={Nav}>
<IndexRoute component={Home}/>
<Route path="articles(/:name)" component={Articles}/>
</Route>
</Router>
<IndexLink to='/' activeClassName="active">{e.name}</IndexLink>
<Link to='/articles' activeClassName="active">{e.name}</Link>
我想的是点击/articles/1 的时候 link articles会被点亮
codelegant
#10
你需要在再裹一层 <Router/>
<Router history={hashHistory}>
<Route path="/" component={Nav}>
<IndexRoute component={Home}/>
<Route path="/articles" component={ArticlesWrap}>
<Route path="/articles/:name" component={Articles}/>
</Route>
</Route>
</Router>
codelegant
#11
按照你的想法,/articles
应该可以使用与 /articles/:name
相同的组件
<Router history={hashHistory}>
<Route path="/" component={Nav}>
<IndexRoute component={Home}/>
<Route path="/articles" component={Articles}>
<Route path="/articles/:name" component={Articles}/>
</Route>
</Route>
</Router>