我正在使用React和React-Router-V4,因为我是React的新手,并且想知道是否有任何我错过的东西。
当我去路线“/”时,它会工作并显示Index
组件,但是当我转到“/ posts / index”时,它不显示任何内容,甚至不显示DefaultPage
组件,是我在index.js
内的路线:
<Switch>
<Route path='/posts/index' component={ShowPosts} />
<Route path='/' component={Index} />
<Route component={DefaultPage} />
</Switch>
答案 0 :(得分:1)
由于我无法发表评论,我认为问题出在webpack.config.js
而不是react-router
,因为您可能没有/
,如果您希望将输出的公共路径提供给会没事的。
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'webpack-index.js',
publicPath: '/'
}
答案 1 :(得分:1)
首先需要将$('#myTable').append(tableUpdate);
添加到索引路由中,否则如果URL路径错误,您的默认页面路由将无效。
exact
关于ShowPosts路线它看起来像组件中的错误,如果可能的话,共享组件代码。