我无法弄清楚如何让我的winjs(react-winjs)应用程序使用硬件后退按钮。这是我的导航功能的一个例子:
handleNavigation(location) {
this.setState({
location: location
});
WinJS.Navigation.navigate(`/${location}`);
console.log(WinJS.Navigation.history);
}
console.log(WinJS.Navigation.history)
输出正确的数组,称为" backStack"使用正确的历史记录顺序,但单击Windows手机模拟器上的硬件后退按钮只是退出应用程序。
我错过了一些明显的东西吗?
这是我设法找到并尝试但没有成功(我确实为C#找到了一些好的文档,但是我不需要的是什么):
由于
答案 0 :(得分:1)
确实这是一个非常愚蠢的错误,我在没有等待winjs / windows准备好的情况下初始化我的应用程序,这就是我应该如何启动它:
Set-Cookie
这样我可以将addEventListener添加到我的组件componentWillMount函数中的“backclick”,它可以工作:
(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();
})();