2017-06-15 81 views
0

试图建立反应路由阵营路由器,最大调用堆栈大小超过

这是我的主要index.js文件

class App extends React.Component{ 

    constructor(props) { 
    super(props); 
    this.state = { 

    }; 
    } 

    render(){ 
    return (
     <Router history={hashHistory}> 
     <Route path={'/'} component={App}> 
      <Route path={'/quizzes'} component={Quiz}> </Route> 
     </Route> 
     </Router> 
    ) 
    }; 
}; 

ReactDOM.render(<App />, 
    document.getElementById('content')); 

我得到的错误说时,遇到了一些奇怪的错误Uncaught RangeError: Maximum call stack size exceeded

不知道为什么

+3

<路由路径= { '/'}成分= {应用}>心不是那个递归? –

+0

,但如果我删除它,我得到'[react-router]位置“/”与任何路由不匹配# –

+0

没关系我现在解决了。设置一个不同的位置/ –

回答

3

你正在渲染你的应用程序,你已经呈现路由器。然后路由器呈现无限循环的应用程序。我觉得你的意思做更多的东西像这样...

class App extends React.Component{ 
 

 
    constructor(props) { 
 
    super(props); 
 
    this.state = { 
 

 
    }; 
 
    } 
 

 
    render(){ 
 
    return (
 
     <div> 
 
     {this.props.children} 
 
     </div> 
 
    ) 
 
    }; 
 
}; 
 

 
ReactDOM.render(
 
     <Router history={hashHistory}> 
 
     <Route path={'/'} component={App}> 
 
      <Route path={'/quizzes'} component={Quiz}> </Route> 
 
     </Route> 
 
     </Router>, 
 
    document.getElementById('content'));
现在,而不是渲染应用这使得路由器,这使得应用程序,你只是渲染路由器在启动,那么因为您可能会测试默认路由......“/”它会根据您的路线呈现应用和任何子组件。

参见:https://github.com/reactjs/react-router-tutorial/tree/master/lessons/02-rendering-a-route

相关问题