如何在webpack中运行run --history-api-fallback

时间:2017-10-06 20:31:09

标签: javascript reactjs webpack react-router-v4



    window.onload = function () {
        var GetDocumentScrollTop = function () {
            var isScrollBodyIE = ASPx.Browser.IE && ASPx.GetCurrentStyle(document.body).overflow == "hidden" && document.body.scrollTop > 0;
            if (ASPx.Browser.WebKitFamily || isScrollBodyIE) {
                if (ASPx.Browser.MacOSMobilePlatform)
                    return window.pageYOffset;
                else if (ASPx.Browser.WebKitFamily)
                    return document.documentElement.scrollTop || document.body.scrollTop;
                return document.body.scrollTop;
            }
            else
                return document.documentElement.scrollTop;
        };
        var _aspxGetDocumentScrollTop = function () {
            if (__aspxWebKitFamily) {
                if (__aspxMacOSMobilePlatform)
                    return window.pageYOffset;
                else
                    return document.documentElement.scrollTop || document.body.scrollTop;
            }
            else
                return document.documentElement.scrollTop;
        }
        if (window._aspxGetDocumentScrollTop) {
            window._aspxGetDocumentScrollTop = _aspxGetDocumentScrollTop;
            window.ASPxClientUtils.GetDocumentScrollTop = _aspxGetDocumentScrollTop;
        } else {
            window.ASPx.GetDocumentScrollTop = GetDocumentScrollTop;
            window.ASPxClientUtils.GetDocumentScrollTop = GetDocumentScrollTop;
        }
    };




我正在使用reactjs路由器,在教程中,他们多数人告诉你写

- 路由器工作的历史 - api-fallback



let path = require('path')
module.exports = {
    entry:path.resolve('public/src/index.js'),
    output: {
        path:__dirname + "/public",
        filename: "bundle.js"
    },
    module: {
        loaders: [{
            exclude: /(node_modules)/,
            loader:'babel-loader',
            query:{
                presets: ['es2015', 'react']
            }
        }]
    },
    watch:true
};

let path = require('path')
module.exports = {
    entry:path.resolve('public/src/index.js'),
    output: {
        path:__dirname + "/public",
        filename: "bundle.js"
    },
    module: {
        loaders: [{
            exclude: /(node_modules)/,
            loader:'babel-loader',
            query:{
                presets: ['es2015', 'react']
            }
        }]
    },
    watch:true
};

{
  "name": "pr_v1",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node server/index.js & webpack",

    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "axios": "^0.16.2",
    "babel-cli": "^6.26.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "body-parser": "^1.18.2",
    "dotenv": "^4.0.0",
    "express": "^4.15.4",
    "moment": "^2.18.1",
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-redux": "^5.0.6",
    "react-router": "^4.2.0",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0",
    "request": "^2.82.0",
    "webpack": "^3.5.5"
  }
}




我是反应路由器的新手,我正试图让--history-api-fallback工作。教程说它把它放在json文件的构建中,但是我没有构建脚本。我想也许它应该是某个地方是webpack配置文件。我不确定。我的问题是我在哪里可以插入--history-api-fallback以便它可以工作。

1 个答案:

答案 0 :(得分:0)

对于webpack dev服务器,您只需添加webpack dev config。这将在您的开发环境中起作用。

devServer: 
{
  historyApiFallback: true
},