事實上,這是一個非常愚蠢的錯誤,我初始化我的應用程序,而無需等待winjs /窗口做好準備,這是我應該initilized它:
(function() {
"use strict";
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// This is how you should initialize your app
ReactDOM.render(<App />, document.getElementById('app'));
} else {
// TODO: This application was suspended and then terminated.
// To create a smooth user experience, restore application state here so that it looks like the app never stopped running.
}
args.setPromise(WinJS.UI.processAll());
}
};
app.oncheckpoint = function (args) {
// TODO: This application is about to be suspended. Save any state that needs to persist across suspensions here.
// You might use the WinJS.Application.sessionState object, which is automatically saved and restored across suspension.
// If you need to complete an asynchronous operation before your application is suspended, call args.setPromise().
};
app.start();
})();
這樣我可以給的addEventListener「backclick」在我的組件componentWillMount功能,它的工作原理:
componentWillMount() {
WinJS.Application.addEventListener("backclick", function() {
document.body.style.background = "red"; //or for example setState/show notification etc...
});
}
其中顯示的代碼,您連接最多此事件處理程序? – Claies
另外,您是否嘗試從第一條路線返回? –
有「鏈接1」和「鏈接3」,忘記添加「鏈接2」 – Lars