事实上,这是一个非常愚蠢的错误,我初始化我的应用程序,而无需等待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