【发布时间】:2017-09-21 20:52:01
【问题描述】:
我的 react-redux 应用中有 2 条路由:
ReactDOM.render(
<Provider store={store}>
<BrowserRouter>
<div>
<Route path = '/a' component = {ContainerComponent} />
<Route path = '/b' component = {ContainerComponent} />
</div>
</BrowserRouter>
</Provider>,
document.getElementById('app'));
- 在http://localhost:8080/a 上我可以看到我的ContainerComponent。
- 在http://localhost:8080/b 上,我还可以看到我的ContainerComponent。
- 但是在http://localhost:8080/a/b 上,我遇到了 404 错误,尽管我希望同时看到两个 ContainerComponents,就像我在许多教程中看到的那样!
我的 webpack 配置:
var HTMLWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
var HTMLWebpackPluginConfig = new HTMLWebpackPlugin({
template: __dirname + '/app/index.html',
filename: 'index.html',
inject: 'body'
});
module.exports = {
entry: __dirname + '/app/index.js',
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}, {
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader?modules,localIdentName="[name]-[local]-[hash:base64:6]"'
})
}]
},
output: {
filename: 'transformed.js',
path: __dirname + '/build'
},
devServer: {
historyApiFallback: true
},
plugins: [
HTMLWebpackPluginConfig,
new ExtractTextPlugin('styles.css')
]
};
【问题讨论】:
-
我很好奇那些教程,它解释了组合 url 路径同时呈现多个组件。据我所知,您的行为是预期的和适当的。
-
这是不可能的。就像@Dez 说的那样,我也对那些通过加入两条路线来呈现多个组件的教程感兴趣。
-
@Dez 例如youtube上的这个(7:00 - 7:20):youtube.com/watch?v=l9eyot_IXLY。我只是在重复他的动作。
-
哦,我明白你想要达到什么目的了。
-
@John Kennedy 我的最终目标是在修改 URL 字符串(添加 JWT 令牌)后将渲染组件保留在屏幕上。目前,在向当前 URL 添加一些字符后,我的组件消失了(错误)。这就是为什么我有兴趣重复这里所做的事情:youtube.com/watch?v=l9eyot_IXLY 7:00 - 7:20,但由于某种原因它对我不起作用......
标签: reactjs react-router react-redux react-router-v4 react-router-dom