React路由器路由通过?

时间:2016-09-05 11:10:50

标签: reactjs react-router

我有以下路线:

<Router history={hashHistory}>
  <Route path='/' component={ContainerApp}>
    <Route component={ContainerAuth}>
      <Route path="login" component={Login}/>
    </Route>
    <Route component={ContainerMain}>
      <IndexRoute component={Home}/>
      <Route path='settings' component={Settings}/>
      <Route path='*' component={NotFound}/>
    </Route>
  </Route>
</Router>

const ContainerApp = (props) => 
  <div>
    {props.children}
  </div>


const ContainerMain = (props) => 
  <div className="mainwrapper">
    <Header />
    <div id="main">
      <div id="wrapper" className="wrapper">
        <DecoratedSidebar />
        <section id="content">
          {props.children}
        </section>
      </div>
    </div>
    <Footer />
  </div>

const ContainerAuth = (props) => 
  <div>
    {props.children}
  </div>

如果我在浏览器中键入url'/ login',它会正确路由到该页面。如果我推动使用:

this.props.router.push({
    pathname: '/login'
});

它呈现ContainerAuth.Login,然后似乎通过并呈现ContainerMain.Home?

这是预期的行为,即是否通过?

1 个答案:

答案 0 :(得分:1)

我来到你面前,我的双腿在我的腿之间,面部红色和底部都被撞了。

注销链接并未阻止默认:

e.preventDefault();