我还尝试将浏览器同步用于单页主干应用程序。
路由更改基本上是在单击锚点时触发的。不幸的是,browser-sync 不能很好地处理具有 stopPropagation 的事件,因此,在其他浏览器中没有触发点击,并且路由已同步。
从那以后,我已经分叉并修复了这个问题以及其他问题,即 mouseup、mousedown、keyup、keydown 和 contenteditable div 的事件同步。
pull-request 仍处于等待状态,因此您可以同时使用来自https://github.com/nitinsurana/browser-sync-client 的 browser-sync-client
您需要进行如下配置才能使修复生效。请注意浏览器同步中不存在的 capture、contenteditable、mouseup 和其他配置选项
var bs = require("browser-sync").create();
var client = require("./");
client["plugin:name"] = "client:script";
bs.use(client);
bs.init({
//server: {
// baseDir: ["test/fixtures"]
//},
proxy: 'http://localhost:8080',
open: false,
minify: false,
snippetOptions: {
rule: {
//match: /SHNAE/,
match: /<\/head>/i,
fn: function (snippet) {
return snippet + "\n</head>";
}
}
},
clientEvents: [
"scroll",
"input:text",
"input:toggles",
"input:keydown",
"input:keypress",
"form:submit",
"form:reset",
"click",
"contenteditable:input",
"mouseup",
"mousedown",
"select:change"
],
ghostMode: {
clicks: true,
scroll: true,
forms: {
submit: true,
inputs: true,
toggles: true,
keypress: true,
keydown: true,
contenteditable: true,
change: true
},
mouseup: true,
mousedown: true
},
capture:true
});