react如何设置默认路由?

现在想把articesList设置为默认路由,点击AppSider里的文章标签去articlesList路由,点击ArticlesList里的文章进入articleDetail路由
App.js

<Layout className="app-container">
  <AppSider />
  <AppContent /></Layout>

AppContent

class AppContent extends React.Component {
  render() {    return (
      <Content className="app-content bg-fff">
        <Switch>
          <Route path="/articleDetail" component={ArticleDetail} />
          <Route path='/articlesList/:tag' component={ArticlesList} />
        </Switch>
      </Content>
    )
  }
}


神不在的星期二
浏览 806回答 2
2回答

慕后森

let&nbsp;Routes&nbsp;=&nbsp;(<Router> &nbsp;&nbsp;<div> &nbsp;&nbsp;&nbsp;&nbsp;<Link&nbsp;activeClassName="active"&nbsp;exact={true}&nbsp;to={{pathname:&nbsp;'/index'}}>首页</Link> &nbsp;&nbsp;&nbsp;&nbsp;<div&nbsp;className="route-content"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<Switch> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<Redirect&nbsp;path="/"&nbsp;to={{pathname:&nbsp;'/index'}}&nbsp;/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</Switch> &nbsp;&nbsp;&nbsp;&nbsp;</div> &nbsp;&nbsp;</div></Router>)exact配合Redirect就可以了

天涯尽头无女友

<Redirect path="/" exact={true} to="/articesList" />
打开App,查看更多内容
随时随地看视频慕课网APP