【问题标题】:Redirecting when listening to WebView Load events in Nativescript.在 Nativescript 中监听 WebView 加载事件时重定向。
【发布时间】:2018-02-26 08:05:36
【问题描述】:

我最近一直在使用 NativeScript 开发我的第一个 Web 应用程序,并且在过去的几天里一直停留在这个问题上。

该应用程序是基于 Nativescript 3.2 构建的,带有 angular

当用户单击按钮然后收听完成的加载事件时,我的应用程序使 web 视图可见。代码按预期工作,直到我尝试重定向到另一个页面。尽管应用程序崩溃了,但我不确定它是否进入了重定向循环。

webViewSetup() {
    let webview: WebView = this.webView.nativeElement;
    let navCount = 0; 

    webview.src = // Backend url

    webview.on(WebView.loadFinishedEvent, function (args: LoadEventData) {

        var res = args.url.substr(0,args.url.indexOf("?")); 

        if(res == // Success page url)
        {
            // Do something 

            if(navCount === 0 ){ // Crashes the application
                this.routerExtension.navigate(["home"],{clearHistory: true});
            }

        }

}


Auth(){
    this.isLoading = true; 
    this.webViewSetup(); 
}  

我希望有人能够解释应用程序崩溃的原因,或者可能是重定向到下一页的更好方法。

【问题讨论】:

    标签: angular typescript nativescript


    【解决方案1】:

    我刚刚遇到了同样的问题。这是您的修复代码。

    webview.on(WebView.loadFinishedEvent, function (args: LoadEventData) {
    
        var res = args.url.substr(0,args.url.indexOf("?")); 
    
        if(res == // Success page url)
        {
            // Do something 
    
            if(navCount === 0 ){ // Crashes the application
                this.routerExtension.navigate(["home"],{clearHistory: true});
            }
    
        }
    
    }, this);
    

    请注意 this 运算符的使用。

    【讨论】:

      猜你喜欢
      • 2018-12-27
      • 2020-11-22
      • 1970-01-01
      • 2018-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-19
      • 1970-01-01
      相关资源
      最近更新 更多