一些路由与 react-router 4 不匹配
Some routes not matching with react-router 4
我在react-router 4中路由匹配有问题,我的路由是:
<Switch>
<Route exact path='/' component={Home} />
<Route path='/communities/create' component={CreateCommunity} />
<Route component={PageNotFound} />
</Switch>
- 对于/,我得到了主页(OK)。
- 对于 /test,我得到了未找到的页面(确定)。
- 对于 /communities/create,我得到一个空白页面(不正常)。
- 对于 /test/2,我得到一个空白页(不正常)
如果我的路线中有多个“/”,我会得到一个空白页面。我怎样才能得到一个空白页?它应该至少是 "Not Found" 页吧。但是对于多个“/”,我得到一个空白页。 None 条路线似乎匹配。
显然,问题与react-router 配置无关。但更多的是与 webpack 配置有关。
我正在使用 historyApiFallback: true 设置和 webpack-dev-server。所有路由都将由 index.html 使用上述配置提供服务。但是当在输出配置中设置 publicPath 时它似乎工作如下:
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/'
},
我能够使用反应样板中的 github issue 解决它。
我在react-router 4中路由匹配有问题,我的路由是:
<Switch>
<Route exact path='/' component={Home} />
<Route path='/communities/create' component={CreateCommunity} />
<Route component={PageNotFound} />
</Switch>
- 对于/,我得到了主页(OK)。
- 对于 /test,我得到了未找到的页面(确定)。
- 对于 /communities/create,我得到一个空白页面(不正常)。
- 对于 /test/2,我得到一个空白页(不正常)
如果我的路线中有多个“/”,我会得到一个空白页面。我怎样才能得到一个空白页?它应该至少是 "Not Found" 页吧。但是对于多个“/”,我得到一个空白页。 None 条路线似乎匹配。
显然,问题与react-router 配置无关。但更多的是与 webpack 配置有关。
我正在使用 historyApiFallback: true 设置和 webpack-dev-server。所有路由都将由 index.html 使用上述配置提供服务。但是当在输出配置中设置 publicPath 时它似乎工作如下:
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
publicPath: '/'
},
我能够使用反应样板中的 github issue 解决它。