Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 处理硬件返回按钮单击_Javascript_Reactjs_Winjs_Windows Applications - Fatal编程技术网

Javascript 处理硬件返回按钮单击

Javascript 处理硬件返回按钮单击,javascript,reactjs,winjs,windows-applications,Javascript,Reactjs,Winjs,Windows Applications,我不知道如何使我的winjs(react winjs)应用程序与硬件后退按钮一起工作。这是我的导航功能的一个示例: handleNavigation(location) { this.setState({ location: location }); WinJS.Navigation.navigate(`/${location}`); console.log(WinJS.Navigation.history); } console.log(Wi

我不知道如何使我的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 phone emulator上的硬件后退按钮只是简单地退出应用程序

我错过了什么明显的东西吗

这是我设法找到并尝试的,但没有成功(我也找到了一些好的C#文档,但不是我需要的):


谢谢

确实这是一个非常愚蠢的错误,我在没有等待winjs/windows准备好的情况下初始化了我的应用程序,我应该这样初始化它:

(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();
})();

显示您连接此事件处理程序的代码在哪里?另外,您是否尝试从第一条路径返回?有“链接1”和“链接3”,忘记添加“链接2”
componentWillMount() {
    WinJS.Application.addEventListener("backclick", function () {
        document.body.style.background = "red"; //or for example setState/show notification etc...
    });
}