我在react-router 4中遇到路由匹配问题。我的路由是:
<Switch>
<Route exact path='/' component={Home} />
<Route path='/communities/create' component={CreateCommunity} />
<Route component={PageNotFound} />
</Switch>
如果我的路线中有多个“/”,我会得到一个空白页面。我怎么能得到一个空白页?它应至少是“未找到”页面。但是对于不止一个“/”,我得到一个空白页面。没有一条路线似乎匹配。
答案 0 :(得分:0)
显然,问题与react-router配置无关。但更多的是与webpack配置有关。
我正在使用historyApiFallback:webpack-dev-server的true设置。所有路线都将由index.html提供,具有上述配置。但是在输出配置中设置 publicPath 时,它似乎有效:
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/'
},
我能够使用react-boilerplate中的github issue来解决它。