Angular 2.0 路由器导航不适用于 iOS WKWebView [英] Angular 2.0 router navigation not working on iOS WKWebView

查看:38
本文介绍了Angular 2.0 路由器导航不适用于 iOS WKWebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于一些性能问题,我正在尝试升级 angularJS2/phonegap 应用程序以在 iOS 上使用 WKWebView.

Because of some performance issues, I'm trying to upgrade an angularJS2/phonegap app to use WKWebView on iOS.

不幸的是,任何对路由导航的调用都不起作用.这包括 routerlinkthis.route.navigate 调用.没有抛出错误.有没有其他人看到过这个和/或可能有解决方法?

Unfortunately, any calls to route navigate do not work. This includes routerlink and this.route.navigate calls. There are no errors being thrown. Has anyone else seen this and/or perhaps have a workaround?

代码使用普通的 UIWebView 可以正常工作.

The code works fine using the normal UIWebView.

我是 Angular 的新手,欢迎提出任何建议.

I'm a relative newbie to Angular so any suggestions are welcomed.

以下是一些相关代码的样子:

Here's what some of the relevant code looks like:

import { Component } from "@angular/core";
import { Routes, Router, ActivatedRoute } from "@angular/router";
import { LoggedInCallback } from "./service/cognito.service";

export class HomeComponent implements LoggedInCallback {

constructor(public router:Router){
}

isLoggedIn(message:string, isLoggedIn:boolean) {
    if (isLoggedIn){
      this.router.navigate(['/home/cl']);
    }
    else {
      console.log('HomeComponent: '+message);
    }
}

路由模块:

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';
import { CategoryListComponent } from './categorylist/categorylist.component';


const approutes: Routes = [
    {
         path: 'home/cl',
         component: CategoryListComponent
    },
    ...
];
@NgModule({
  declarations: [

 ],
  imports: [RouterModule.forRoot(approutes), 
        BrowserModule, 
        FormsModule],
  exports: [RouterModule]

})
export class AppRoutingModule { }

回应以下评论:

如前所述,这是一个 phonegap 应用程序,因此大多数参考文献都使用(我假设)文件:协议.但是,第一页加载正常,并且它引用了单个 JavaScript 文件中的内容.奇怪的是,所有其他路由器引用的内容也都在同一个 JavaScript 文件中.

As mentioned, this a phonegap app, so most of the references are using (I assume) the file: protocol. However, the first page loads okay, and it references content within a single JavaScript file. The odd thing is that all of the other router-referenced content are also in that same JavaScript file.

我希望有人能够理解路由器行为的具体细节,以解释为什么它在这种环境中不起作用.

I was hoping that someone would understand the nuts and bolts of the router behavior to explain why it doesn't work in this environment.

推荐答案

您是通过网络服务器还是通过 file://协议访问?wkwebview 似乎有这个问题.

Are you accessing this through a web server or file:// protocol? It seems wkwebview has issues with that.

查看这篇文章

这篇关于Angular 2.0 路由器导航不适用于 iOS WKWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆