Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2.0 router navigation not working on iOS WKWebView

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.

like image 261
Mike M Avatar asked Nov 10 '16 23:11

Mike M


1 Answers

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

See this article

like image 171
PersyJack Avatar answered Oct 25 '22 02:10

PersyJack