2016-07-26 168 views
1

我的/路由不能正确呈现我的主要组件。React JS路由不能正常工作

这里是我的代码:

ReactDOM.render(
    <Router history={browserHistory}> 
     <Route path="/" componenet={Main}> 
      <IndexRoute component={Index}></IndexRoute> 
      <Route path="portfolio" component={Portfolio}></Route> 
     </Route> 
    </Router>, 
    document.getElementById('app') 
); 

这是我的主要成份:

export default class Main extends React.Component {  
    render() { 
     console.log("asdfasfsaf"); 
     return(
     <div> 
      <h1> This is Main Page </h1> 
      {this.props.children} 
     </div> 
     ) 
    } 

} 

一旦我打开这个网站,它进入我的Index组件。然而它并没有呈现Main.js<h1> This is Main Page </h1>。然后我完全清除Main.js中的所有代码并重新加载,并看到它仍然没有任何错误地运行。有没有人知道这个解决方案?

+0

peroperly>正确,组元>组件:) –

回答

1

你有一个错字这里<Route path="/" componenet={Main}>组件

ReactDOM.render(
    <Router history={browserHistory}> 
    <Route path="/" component={Main}> 
     <IndexRoute component={Index}></IndexRoute> 
     <Route path="portfolio" component={Portfolio}></Route> 
    </Route> 
</Router>, 
document.getElementById('app') 
); 

export default class Main extends React.Component {  
    constructor(props) { 
    super(props) 
    } 
    render() { 
    console.log("asdfasfsaf"); 
    return(
     <div> 
      <h1> This is Main Page </h1> 
      {this.props.children} 
     </div> 
    ) 
    } 
}