Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 使用webpack生成应用程序后,React路由不工作_.htaccess_Reactjs_Webpack_Webpack Dev Server - Fatal编程技术网

.htaccess 使用webpack生成应用程序后,React路由不工作

.htaccess 使用webpack生成应用程序后,React路由不工作,.htaccess,reactjs,webpack,webpack-dev-server,.htaccess,Reactjs,Webpack,Webpack Dev Server,使用webpack生成应用程序后,React路由不工作 当我使用网页包服务器(npm start)运行应用程序时,路由工作正常 webpack.config文件 var webpack = require('webpack'); module.exports = { entry: { 'index': [ 'webpack-dev-server/client?http://localhost:8080/', 'webpac

使用webpack生成应用程序后,React路由不工作

当我使用网页包服务器(npm start)运行应用程序时,路由工作正常

webpack.config文件

var webpack = require('webpack');

module.exports = {
    entry: {
        'index': [
            'webpack-dev-server/client?http://localhost:8080/',
            'webpack/hot/only-dev-server',
            './index.jsx'
        ]
    },
    output: {
        path: __dirname,
        filename: "[name].js",
        publicPath: 'http://localhost:8881/',
        chunkFilename: '[id].chunk.js',
        sourceMapFilename: '[name].map'
    },
    resolve: {
        extensions: ['', '.js', '.jsx', '.es6'],
        modulesDirectories: ['node_modules']
    },
    module: {
        loaders: [
            {test: /\.jsx$|\.es6$|\.js$/, loaders: ['react-hot', 'babel-loader'], exclude: /node_modules/},
            {test: /\.scss$|\.css$/, loader: 'style-loader!style!css!sass'}
        ]
    },
    plugins: [
        new webpack.NoErrorsPlugin()
    ],
    devtool: "eval-source-map",
    devServer: {
        port: 8080,
        historyApiFallback: {
            index: '/'
        }
    },
    externals: {
        'Config': JSON.stringify({
            serverUrl: "http://pss/",
            authSuccessUrl: "http://localhost:8881/loginSuccess",
            podioClientId: "property-seller-solutions"
        })
    }
};
package.json文件:

{
  "name": "pss",
  "version": "0.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --config ./webpack.config.js --hot --port 8080"
  },
  "author": "",
  "license": "BSD-2-Clause",
  "devDependencies": {
    "babel": "~6.5.2",
    "babel-core": "~6.9.1",
    "babel-loader": "~6.2.4",
    "babel-preset-es2015": "~6.9.0",
    "babel-preset-react": "~6.5.0",
    "babel-preset-stage-0": "~6.5.0",
    "gulp": "^3.9.1",
    "gulp-concat": "^2.6.0",
    "gulp-html-replace": "^1.6.1",
    "gulp-react": "^3.1.0",
    "gulp-uglify": "^1.5.4",
    "history": "~3.0.0",
    "react": "~15.1.0",
    "react-dom": "~15.1.0",
    "react-hot-loader": "~1.3.0",
    "webpack": "~1.13.1",
    "webpack-dev-server": "~1.14.1"
  },
  "dependencies": {
    "chart.js": "^2.1.6",
    "connect-history-api-fallback": "~1.2.0",
    "halogen": "^0.2.0",
    "highcharts": "^4.2.5",
    "react-d3-basic": "^1.6.11",
    "react-infinite-scroll-component": "^1.4.1",
    "react-infinite-scroll-es2015": "^1.0.0"
  }
}
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
.htaccess文件:

{
  "name": "pss",
  "version": "0.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --config ./webpack.config.js --hot --port 8080"
  },
  "author": "",
  "license": "BSD-2-Clause",
  "devDependencies": {
    "babel": "~6.5.2",
    "babel-core": "~6.9.1",
    "babel-loader": "~6.2.4",
    "babel-preset-es2015": "~6.9.0",
    "babel-preset-react": "~6.5.0",
    "babel-preset-stage-0": "~6.5.0",
    "gulp": "^3.9.1",
    "gulp-concat": "^2.6.0",
    "gulp-html-replace": "^1.6.1",
    "gulp-react": "^3.1.0",
    "gulp-uglify": "^1.5.4",
    "history": "~3.0.0",
    "react": "~15.1.0",
    "react-dom": "~15.1.0",
    "react-hot-loader": "~1.3.0",
    "webpack": "~1.13.1",
    "webpack-dev-server": "~1.14.1"
  },
  "dependencies": {
    "chart.js": "^2.1.6",
    "connect-history-api-fallback": "~1.2.0",
    "halogen": "^0.2.0",
    "highcharts": "^4.2.5",
    "react-d3-basic": "^1.6.11",
    "react-infinite-scroll-component": "^1.4.1",
    "react-infinite-scroll-es2015": "^1.0.0"
  }
}
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
构建应用程序(webpack--hot--inline)后,得到了两个输出文件——index.js和index.html

我将这两个文件和.htaccess文件复制到本地主机根文件夹中

索引路由工作正常..(),但当我尝试重定向到它时,显示“404未找到”错误(在此服务器上未找到请求的URL/home)


当我使用webpack服务器(npm start)运行应用程序时,这些路由工作正常-

据我所知,如果您说它将进行服务器端路由器调用。你需要先安装它


您需要将应用程序配置为在访问/主页时提供index.html。

有效

使用了以下.htaccess代码:

RewriteEngine On  
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]

RewriteRule ^ /index.html [L]
并使用以下终端命令使用webpack构建项目:

webpack --inline --history-api-fallback --progress -p

林克死了。我可以建议下一个答案,把报价从您所附的情况下,我们这里的情况?