Angular 2.0路由器导航在iOS WKWebView上不起作用 [英] Angular 2.0 router navigation not working on 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.
很遗憾,路由导航的任何呼叫均无法正常工作.这包括routerlink
和this.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.
以下是一些相关代码:
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.
推荐答案
您是通过Web服务器还是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屋!