关于react-route中link

#1

可以给link设置activeClassName;但是当有二级页面的时候一级页面的claa就失效了 ;
我的给导航 /index设置了
在/index/a的时候activeClassName 失效了
是否 /index/a链接的时候就不用link了 就直接用a就可以了

#2

一级页面使用了 <IndexLink/> 吗?

#4
<IndexLink to={e.url} activeClassName="active">{e.name}</IndexLink>

<Link to={e.url} activeClassName="active">{e.name}</Link>
#5

下面还有二级链接 这是一级的

#6

一级页面使用一般的 <Link/> 就好,使用了 <IndexLink/> 就是你目前这个效果。二级页面不会激活使用 <IndexLink/> 的一级页面。

#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不会被激活了

#8

可否将路由配置贴出来?

#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会被点亮

#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>
#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>
#12

对的 谢谢了 就是这样的