简体   繁体   English

webpack-dev-server不使用React-Router参数路由从配置位置提供包

[英]webpack-dev-server not serving bundle from config location with react-router param route

Using react-router my routes match and my app bundle SearchUXBundle.js correctly loads from first level routes - but second level routes /tracker/:id incorrectly are trying to load my app bundle from localhost/tracker/dist/SearchUXBundle.js instead of localhost/dist/SearchUXBundle.js. 使用react-router我的路由匹配并且我的应用程序包SearchUXBundle.js从第一级路由正确加载-但是第二级路由/ tracker /:id错误地试图从localhost / tracker / dist / SearchUXBundle.js而不是从我的应用程序加载本地主机/dist/SearchUXBundle.js。 im assuming this is some kind of config wrinkle in webpack 'output' relating to relative paths that im missing... 我假设这是webpack'输出'中的某种配置皱纹,与我缺少的相对路径有关...

webpack.config,js webpack.config,js

var path = require('path');
var webpack = require('webpack');

module.exports = {
  devtool: 'source-map',
  devServer: {
        inline:false,
        port: 8001,
        historyApiFallback: true 
  },
  entry: {
    app: ['./src/root.js']
  },

  output: {
          path: "/dist",
          publicPath: '/',
          filename: '/dist/SearchUXBundle.js'
    },
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel',
        query: {
          retainLines: true,
          cacheDirectory: true
        }
      },
      {
        test: /.css$/,
        loaders: ['style', 'css']     
      },
      { test: /\.(png|jpg|jpeg|gif|woff)$/, loader: 'url-loader?limit=8192' },
    ]
  },
  resolve: {
      alias: {
          __CONFIG__: path.join(__dirname, 'config', process.env.REACT_ENV)
      }
  }
};

app.js app.js

...
const store = createStore(rootReducer, enhancer);
const history = syncHistoryWithStore(browserHistory, store, {
  selectLocationState: createSelectLocationState()
});

render(
  <Provider store={store} >
     <Router history={history}> 
        <Route path="/" component={SearchUXContainer} />
        <Route path="tracker/:id" component={EmailTrackerContainer}/>
        <Route path="thisWorks" component={SearchUXContainer}/>
     </Router>
  </Provider>,
  document.getElementById('app')
);

You need to make sure that the linked bundle in your index.html file is absolute. 您需要确保index.html文件中的链接包是绝对的。 If it is relative, then the location will vary based on the URL and any nested routes will point to a non-existent location. 如果是相对的,则位置将根据URL而变化,并且任何嵌套路由都将指向不存在的位置。

<!-- bad -->
<script src="dist/SearchUXBundle.js"></script>

<!-- good -->
<script src="/dist/SearchUXBundle.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM