我目前正在設置一個使用webpack-dev-server和骨幹路由器的站點。Webpack dev服務器無法加載嵌套的網址(GET 404錯誤)
直到今天,一切似乎是工作(例如我可以去http://localhost:3333
我的主頁和http://localhost:3333/login
我的登錄頁面。
但今天我試着去我的第一個嵌套鏈接,http://localhost:3333/people/1
,和我的控制檯拋出一個404 GET錯誤
確切的錯誤是這樣的:。 http://localhost:3333/people/build/bundle.js 404 (Not Found)
看來,我的WebPack服務器正在試圖尋找正確的文件到服務器錯誤的目錄下,如果這是正確的,我不知道 如何解決這個問題。我看過其他堆棧溢出問題和github問題,但無濟於事。有什麼想法嗎?
我使用gulp啓動服務器。這裏是我的gulpfile:
var gulp = require("gulp");
var webpack = require("webpack");
var server = require("webpack-dev-server");
var config = require("./webpack.config");
gulp.task("serve", function() {
new server(webpack(config), {
publicPath: config.output.publicPath,
historyApiFallback: true,
hot: true,
quiet: false,
stats: { colors: true, progress: true },
}).listen(3333, "localhost", function (err, result) {
if (err) {
console.log(err);
} else {
console.log("Listening at localhost:3333!");
}
});
});
gulp.task("default", ["serve"]);
這裏是我的WebPack配置文件:
var webpack = require("webpack");
module.exports = {
entry: [
__dirname + "/app/app.js",
"webpack/hot/dev-server",
"webpack-dev-server/client?http://localhost:3333/",
],
output: {
path: __dirname + "/build",
filename: "bundle.js",
publicPath: "http://localhost:3333/",
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
module: {
loaders: [
{ test: /\.jsx$/, exclude: /node_modules/, loader: "react-hot-loader!babel-loader" },
{ test: /\.js$/, exclude: /node_modules/, loader: "babel-loader" },
{ test: /\.scss$/, exclude: /node_modules/, loader: "style!css!sass" },
]
},
resolve: {
root: __dirname,
extensions: ["", ".js", ".jsx"],
},
}
編輯:我剛剛發現,我可以直接打網址http://localhost:3333/#/people/1
或http://localhost:3333/#people/1
,一切按預期工作。
是否有一個設置,可以讓我不必在url中包含磅符號?希望這有助於給我的問題提供更多的背景。
跟進:我有一個全球App
組件初始化骨幹路由器,並呼籲Backbone.history.start({ pushState: true })
。這是一段代碼片段。
class App {
constructor() {
console.log("starting up");
this.Router = new Router();
Backbone.history.start({ pushState: true });
}
}
module.exports = new App();
如果您發現在構造函數中console.log
,這就是所謂的能夠使非嵌套頁,但不能在嵌套頁面不了的。
最明顯的錯誤有時是最難捕捉到的。感謝您節省我的時間和挫折:) – Pandaiolo