Angular 2.0 router navigation not working on iOS WKWebView

拜拜、爱过 提交于 2020-03-21 11:26:07

问题


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

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?

The code works fine using the normal UIWebView.

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

routing module:

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 { }

In response to a comment below:

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.


回答1:


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

See this article



来源:https://stackoverflow.com/questions/40538510/angular-2-0-router-navigation-not-working-on-ios-wkwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!