React router not displayed a component

时间:2016-02-12 21:37:39

标签: reactjs react-router

org.gradle.jvmargs=-Xmx1024m

The component did not display after using react router (only SiteLanding component displayed ). when i tried removing the router, and rendering App component directly, navigation component rendered properly. Is there anything wrong with my routing configuration

1 个答案:

答案 0 :(得分:1)

您的react-router设置根本不会渲染您的App组件。它将直接将SiteLanding呈现在' /'和KanbanBoard在' /仪表板'。在这种情况下你想要的可能看起来更像是这样:

ReactDOM.render((
    <Router>
        <Route path="/" component={App} />
          <IndexRoute component={SiteLanding} />
          <Route path="dashboard" component={KanbanBoard} />
        </Route>
    </Router>), document.getElementById('root'));

这样,您就拥有了在每个路径上呈现的根组件(App),并且传递给它的子组件具有可变性。确保在顶部导入IndexRoute组件以使其正常工作。

我建议同时添加某种URL历史记录管理功能 - 有关详情,请参阅https://github.com/reactjs/react-router/blob/latest/docs/Introduction.md