react-router-dom: 重定向默认路由

<appLayout>
      <Switch>
          <Route path='/' exact render={()=> (
               <Redirect to={this.getDefaultRoute()}/>
           )}/>
        Switch>
appLayout>

根据登录与否进入自定义路由

只能判断根路由,子路由不受影响需做另外设置

redirectDefault() {
  const defaultState = this.state.defaultState}/>
  const loginState = 
  return this.state.hasLogin ? defaultState : loginState;
}

 

转载于:https://www.cnblogs.com/Nyan-Workflow-FC/p/8759683.html

你可能感兴趣的:(react-router-dom: 重定向默认路由)