<appLayout> <Switch> <Route path='/' exact render={()=> ( <Redirect to={this.getDefaultRoute()}/> )}/> </Switch> </appLayout>
根据登录与否进入自定义路由
只能判断根路由,子路由不受影响需做另外设置
redirectDefault() { const defaultState = <Route to={this.state.defaultState}/> const loginState = <Route to="/login"/> return this.state.hasLogin ? defaultState : loginState; }