2017-07-24 98 views
1

我有問題,路由器新的路由器的反應,登錄後,我在終極版從0變爲1型狀態,然後我讓開關在我的應用程序文件,但我得到了錯誤反應。登錄後

Warning: [react-router] You cannot change <Router routes>; it will be ignored 

這是我的index.js,我想改變這一切路線鏈接,如果用戶是登錄(表格登錄工作好,他們改變Redux的狀態類型:1):

@connect((store)=>{ 
    console.log(store) 
    return { 
     typeUser: store.app.type 
    } 

}) 
class App extends React.Component{ 

    render(){ 
     switch(this.props.typeUser){ 
      case 0:{ 
     return(
     <Router history={browserHistory}> 
      <Route path={"/"} component={MainPage}></Route> 
      <Route path={"/login"} component={Login}></Route> 
      <Route path={"product/:nameProduct/:id"} component={ProductDetails}></Route> 
     </Router> 
     ) 
     break; 
     } 
      case 1:{ 
       return(
       <Router history={browserHistory}> 
        <Route path={"/"} component={MainPageAfterLogin}></Route> 
        <Route path={"/login"} component={LoginAfterLogin}></Route> 
       </Router> 
       ) 
       break; 
      } 
    } 
    } 
} 

const app = document.getElementById('app'); 
ReactDOM.render(<Provider store={store}> 
    <App/> 
    </Provider>,app); 

回答

0

你不能改變的Router,但你可以改變Routes構造你有,所以你可以設置路線,如

class App extends React.Component{ 
 
    render(){ 
 
     
 
     return(
 
     <Router history={browserHistory}> 
 
      {this.props.typeUser === 0? <User1/>: <User2/>} 
 
      
 
     </Router> 
 
     ) 
 
     
 
    } 
 
} 
 

 
class User1 extends React.Component { 
 
    render() { 
 
    return (
 
     <div> 
 
       <Route path={"/"} component={MainPage}></Route> 
 
       <Route path={"/login"} component={Login}></Route> 
 
       <Route path={"product/:nameProduct/:id"} component={ProductDetails}></Route> 
 
     </div> 
 
    ) 
 
    } 
 
} 
 

 
class User2 extends React.Component { 
 
    render() { 
 
    return (
 
     <div> 
 
       <Route path={"/"} component={MainPage}></Route> 
 
       <Route path={"/login"} component={Login}></Route> 
 
       
 
     </div> 
 
    ) 
 
    } 
 
}

+0

檢查更新的answere –